my dog learned polymorphism
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Khalid's question on Inner 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 "Khalid Watch "Khalid New topic

Khalid's question on Inner class

aishwarya mathur

Joined: Sep 03, 2004
Posts: 22
Hi All,

Here "sunil" get printed.Can explain why?
Doyle Matt
Ranch Hand

Joined: Jul 05, 2004
Posts: 76
Inner classes are no my specialty but here goes

new Example().new Inner().doIt();

what this one does is it:
first : creates and object of Example
second: using that object of Example it creates an inner object of Inner
third : using that inner object it calls the doIt function of the Inner object

SCJP 1.4
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Notice that class Object, which your Example class inherits, does not have a member or method called new (I'm talking about the .new). It's a part of the syntax of the java Language which is understood by the compiler.

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:
subject: Khalid's question on Inner class
It's not a secret anymore!