[I added UBB CODE tags to your source code to make it more readable. Please try to use them in the future. Learn more about UBB codes here - Ajith ]
[This message has been edited by Ajith Kallambella (edited October 31, 2000).]
Brian, Cavanagh
Ranch Hand
Joined: Oct 30, 2000
Posts: 70
posted
0
why does q.x return 7 as well???
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 3901
posted
0
what does q.getY() return?
I never took notes in college. That's how I got a 4.0 the first 2 years, and a 3.5 the second two years.
Sagar Sharma
Ranch Hand
Joined: Aug 31, 2000
Posts: 92
posted
0
hi, Method calls are always determined by the state of the object at runtime, but the variables are referenced using the reference of the object. Since object q has a reference variable of type Shape q.y will always give 7. Same is the case for q.x. Hope this helps
sagar
Randall Twede
Ranch Hand
Joined: Oct 21, 2000
Posts: 3901
posted
0
so q.getY() returns 5 ?
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5781
posted
0
PROPER NAMES ARE NOW REQUIRED!! Read this post for more details. Javaranch appreciates your cooperation to comply with the official naming policy. Ajith
Open Group Certified Master IT Architect.
Sun Certified Architect(SCEA).
Allan Tan
Greenhorn
Joined: Oct 31, 2000
Posts: 7
posted
0
q.y() returns 5. Thanks!
SHALINI PATEL
Ranch Hand
Joined: Oct 31, 2000
Posts: 41
posted
0
I think u r referring to variable and method shadowing. When u invoke a method by an object it is a class of the current object and not the type of reference. example... //Tubelight extends light and has a method called getBill() Light l1 = new Tubelight() Hence if yu want to excess getBill yu just say li.getBill(); But the variable accessed is from the class corresponding to the reference type regardless of the object denoted by reference. example. //If both Light and Tubelight class has an instance variable int x1 Light l1 = new Tubelight() Then if yu invoke l1.x1 then its the instance variable of light class that is invoked. I hope yu get it. Hope somebody can correct me if I am wrong. shalini
Ajith Kallambella
Sheriff
Joined: Mar 17, 2000
Posts: 5781
posted
0
shalini you are right except for the terminology. Instance methods can be overridden by subclasses. Static methods gets shadowed or hidden when redefined by the subclass(es). Overriding does not apply to static methods. Variables( static or instance ) gets hidden or shadowed when redeclared by subclass(es) because the name resolution starts from the immediate enclosing scope. Just my two cents worth.... Ajith