Thread: Static Methods
View Single Post
  #4 (permalink)  
Old June 9th, 2009, 08:31 PM
Old Pedant Old Pedant is offline
Friend of Wrox
Points: 4,805, Level: 29
Points: 4,805, Level: 29 Points: 4,805, Level: 29 Points: 4,805, Level: 29
Activity: 38%
Activity: 38% Activity: 38% Activity: 38%
 
Join Date: Jun 2008
Location: Snohomish, WA, USA
Posts: 1,323
Thanks: 3
Thanked 70 Times in 69 Posts
Default

You seem to have just said the same thing I said, in different words.

So I really do not understand your "doubt."

The point is, when you code
Code:
       public static int getAge(Practice prac)
       {
            return prac.age;
       }
the member age that you are getting there is *NOT* the CLASS variable named age. It is the OBJECT member that is a member of the REFERENCE "prac" that you passed to the function.

There is nothing illegal at all about getting a member of a referenced instance, no matter where. The fact that your getAge method is static is IRRELEVANT.
Reply With Quote