Results 1 to 6 of 6

Thread: static methods in object oriented programming

  1. #1
    Join Date
    Dec 2010
    Posts
    59

    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 .

  2. #2
    Join Date
    May 2009
    Posts
    511

    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.

  3. #3
    Join Date
    May 2009
    Posts
    543

    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.

  4. #4
    Join Date
    May 2009
    Posts
    529

    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.

  5. #5
    Join Date
    Apr 2009
    Posts
    569

    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.

  6. #6
    Join Date
    May 2009
    Posts
    529

    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
    .......... 
    .......... 
    }

Similar Threads

  1. Object oriented programming with java
    By cloud101 in forum Software Development
    Replies: 2
    Last Post: 22-02-2012, 01:11 AM
  2. Replies: 4
    Last Post: 11-07-2011, 02:39 PM
  3. Replies: 3
    Last Post: 08-01-2011, 06:23 AM
  4. Replies: 3
    Last Post: 08-01-2011, 06:20 AM
  5. The OOP Object Oriented programming Concept & its principle?
    By Bhavya in forum Software Development
    Replies: 3
    Last Post: 25-02-2009, 09:16 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,415,340.49058 seconds with 17 queries