aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on anonymous class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on anonymous class" Watch "Question on anonymous class" New topic
Author

Question on anonymous class

Yuva Raj Sah
Greenhorn

Joined: Apr 28, 2004
Posts: 6
For the code:

The output is:
Super method
Sub method

Does that mean the reference s refers to the anonymous sub class ? a bit confused.

(code tags added)
[ May 21, 2004: Message edited by: Barry Gaunt ]
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729


The above code makes a new object from a subclass of class Super. The new subclass has been provided with a new implementation of method method1 which overrides the base class' implementation. Then that new object has been assigned to the variable s which is of type Super, the base class. When s.method1() is executed, the subclass' version of method1 gets called (normal polymorphism behaviour).


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Yuva Raj Sah
Greenhorn

Joined: Apr 28, 2004
Posts: 6
Thanks for clarification.

Yuvaraj
 
wood burning stoves
 
subject: Question on anonymous class