aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Accessing method in a static 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 "Accessing method in a static Inner Class" Watch "Accessing method in a static Inner Class" New topic
Author

Accessing method in a static Inner Class

Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
cosidering this code is it possible to access aMethod()?? if it is, then how?


- Do not try and bend the spoon. That's impossible. Instead, only try to realize the truth. - What truth? - That there is no spoon!!!
Krishna Srinivasan
Ranch Hand

Joined: Jul 28, 2003
Posts: 1844

to access method from static inner class there is no need of Outer class instance.since it is static we can use the direct name.
Outer.Inner.amethod();


Krishna Srinivasan
Spring Tutorials, OCAJP Mock Questions, 400+ OCPJP Mock Questions
Vicken Karaoghlanian
Ranch Hand

Joined: Jul 21, 2003
Posts: 522
the code you posted will be true iff the aMethod was static (which isn't)
add the following code to previous and see the result yourself

both ways(line 1 & 2) to access aMethod() failed... i think it is impossible to reach, anyone else agrees???
sopal Pal
Ranch Hand

Joined: Aug 04, 2003
Posts: 83
You can do something like this, this works
==================
public static void main(String[] args)
{
Outer.Inner i = new Outer.Inner();
i.aMethod();
}
================


SCEA, SCBCD, SCJP1.4, OOAD-UML, OCP 9i
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Accessing method in a static Inner Class