This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Polymorphic method invocations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Polymorphic method invocations" Watch "Polymorphic method invocations" New topic
Author

Polymorphic method invocations

sura watthana
Ranch Hand

Joined: Sep 13, 2004
Posts: 77
Hi
I need an explanation.
Let's look at the code below before the question is to be asked.









i know that
Polymorphic method invocations apply only to instance methods. You can always refer to an object with a more general reference variable type (a superclass or interface), but at runtime, the ONLY things that are dynamically selected based on the actual object (rather than the reference type) are instance methods. Not static methods. Not variables. Only overridden instance methods are dynamically invoked based on the real object's type.


problem is I don't get it.
question is why can't variable be called when it comes to


I thought it'd make sense to do so.
Could anyone give me an explanation to this.


Thanks

Sura
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Your properties have been declared with no scope so they have default scope. Lession1 cannot access these properties.
ahmed yehia
Ranch Hand

Joined: Apr 22, 2006
Posts: 424
Variables 'gs' and 'pp' have default access. Only classes in the same package can access them.
Burkhard Hassel
Ranch Hand

Joined: Aug 25, 2006
Posts: 1274
Howdy,

I don't see your problem. Since you didn't have a package statement, all this classes go into the default package. Hence all fields are visible.

Your classes compile without an error and print out the values as expected.


Yours,
Bu.


all events occur in real time
Michael Ku
Ranch Hand

Joined: Apr 20, 2002
Posts: 510
Let's ask the source.

sura, are the classes all in the same package? are they all in the default package?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Polymorphic method invocations
 
Similar Threads
Object Reference Question
Oveririding confusion
Object Reference Question
Regarding reference variable