TechArena Community

TechArena Community (http://forums.techarena.in/)
-   Software Development (http://forums.techarena.in/software-development/)
-   -   static methods in object oriented programming (http://forums.techarena.in/software-development/1382674.htm)

Satchel 25-12-2010 06:20 AM

static methods in object oriented programming
 
I am a student of Third year , I have subjects like SQL, ERP , implementation , Supply chain management and Customer relationship management and programming languages like Core JAVA and C# in my third year, although my third year has just began but still it is one of the important year of my career , I have my unit test on my head the upcoming week, however one concept in my C# subject is not clear and and that is the static data members, it was covered there in the Core Java last semester , so it will be of much more help if you could provide of necessary information. I would appreciate if any programmer or developer replies .

Vandam 25-12-2010 06:28 AM

Re: static methods in object oriented programming
 
Static data members are those data members which are referred without the reference of any object. The scope of any static data member is not restricted to any particular object. Like a normal variable , which is accessed with the help of a dot operator , it does not happen at all with these static data member, they are directly referred or called with the class name.

Jacques25 25-12-2010 06:53 AM

Re: static methods in object oriented programming
 
A C# class can enclose both static and non-static data members. When we initiate a member and make the use of the keyword static, it produces a static member. This type of data member does not belong to any object but rather belong to the class Therefore static data members are also known as class data members and non-static data members are called as instance members.Bear in mind that indexers in C# can't declared as static and if you do not mention the keyword static then it is by default non static.

Author 25-12-2010 06:54 AM

Re: static methods in object oriented programming
 
The standard way to interact with a class, is to make a new object of the class, and then operate on the resulting object. In the majority cases, this is what basic constructs are all about - the capacity to instantiate more than one copy of the that class and then utilize them in a different way. However, in a few cases, you may like to have a class which you may utilize without creating any object . For example, you will have a class with a identifier that in most cases remains the same, it does not matter at all how it is being used and where it is being used . This is known a static data member. static because it remains the same.

Dwarner 25-12-2010 06:54 AM

Re: static methods in object oriented programming
 
Whenever any object of an class is created with the new keyword , a new copy of that variable or member is allocated is time it the class is instantiated , and to access that data member you will have to take the reference of that object , but a static data member creates only one copy and only that copy is available to the whole code throughout, and if you want to access that data member you will have to access it with the class name.

Author 07-01-2011 09:58 PM

Re: static methods in object oriented programming
 
The static member functions do not have an object scope and they do not possess any sort of control over 'this' pointer of the class. When a function is declared as static that is a static method of that class creates only one copy , that is that function or method itself throughout the whole program The major practice of static method is when the programmer requires to have a method which is available even when the class?s object is not created .


Code:

static return _type method_name()
//Static method defined with static keyword
{
statement1;
statement2;
//Statements for execution inside static method
..........
..........
}



All times are GMT +5.5. The time now is 01:52 PM.