Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question from Roundup game Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question from Roundup game" Watch "Question from Roundup game" New topic
Author

Question from Roundup game

Peixiao Lin
Greenhorn

Joined: Oct 04, 2004
Posts: 28

---------------------------------------------------
Thanks for reply.
[ October 07, 2004: Message edited by: Barry Gaunt ]
Anthony Villanueva
Ranch Hand

Joined: Mar 22, 2002
Posts: 1055
It helps to read your post if you enclose it in code tags.

Since an scjp object is also an instance of the exam class, each scjp object inherits the public print() method. But this inherited method can only "see" the member x of the parent class, namely x="easy". Try variants of this code by overriding print() in scjp, or changing access modifiers.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
When a.print() is executed, the context of the method is the base class part of the object. So the value of x is "easy".

If you define a print method in class scjp then the context of the print method will be the scjp class. Then "killing" will be printed.

Compile the classes, and play with the application by moving the print method from base class to derived class. See what happens when you define print in both classes. Change the type of the variable a to exam. What happens?

Fifteen minutes play will teach you a lot about this topic.


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question from Roundup game