• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Qa dd'rouy Again  RSS feed

Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

as you know the answer is
Show method in Test Class
Show method in Question Class
but if i will change little bit code in main as ....
public static void main(String args[]) {
Test4 t=new Question4();
Question4 q=new Question4();

answer is same ..i am so confuse b/c i learn as in polymorphism...
JVM consider object type not Refernce type .. so why output is not
Show method in Question Class
Show method in Question Class
i think it's because of static context .. please give me the description...
as you can ( go indepth of concepts )what's the reason behind all ...??
please please ...
Umair Uddin Qa dd'rouy
[This message has been edited by Cindy Glass (edited October 05, 2001).]
High Plains Drifter
Posts: 7292
Netbeans IDE VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Polymorphism is just a concept, not an "implementation detail" of Java; the concrete behavior you're looking for is more properly called "run-time" binding. Run-time binding makes it possible to address an object in memory by any valid reference type, and still get the "local" behavior of the object itself. This assumes, of course, that the same behavior is accessible from both the compile-time reference and the run-time object.
Now if a method is declared static, its behavior belongs to the immediate class. It then no longer matters what reference type you point to: t.show() will always be a class-level invocation.
Michael Ernest, co-author of: The Complete Java 2 Certification Study Guide
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The methods show () that you create are static. If they were instance methods, then the "polymorphism" that you are referring to would work as you expect it. Take the static keyword away from the methods and it will work. This is probably not a full explanation, someone else help please?
"The Hood"
Posts: 8521
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that you explained it well.
In order for the statement:
Test4 t=new Question4();
to print "Show method in Question Class" there would have to be some late binding going on so that the Question4 method could get picked up in preference over the Test4 method of the variable type that t is. There is no late binding involved with variables or static stuff, so the static method of Test4 gets called - cuz that is the type that the variable is.
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!