aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inner class confusion 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 "Inner class confusion" Watch "Inner class confusion" New topic
Author

Inner class confusion

sarvesh dikonda
Ranch Hand

Joined: Apr 08, 2012
Posts: 58



i want to know how come the above code runs without any compilation errors.Because looking at the code initially, i thought that it wouldn't compile as, one cannot define a class inside the main() of a class and even if it is allowed, what is the use of defining the class String in class MyClass as i can't see what is its use? Kindly reply.
Source- friend


Always believe in yourself
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

sarvesh dikonda wrote:
i want to know how come the above code runs without any compilation errors.Because looking at the code initially, i thought that it wouldn't compile as, one cannot define a class inside the main() of a class


See => Example 8.1.3-2. Inner Class Declarations

From JLS (<-- click)

sarvesh dikonda wrote:
and even if it is allowed, what is the use of defining the class String in class MyClass as i can't see what is its use?

some times, it may better to put related things together. for example,



Ofcourse, It may not be a good design.
but it has one advantage you cant access this class object outside this method, unless you escape intentionally .

sarvesh dikonda wrote:
Source- friend


Sounds, String s="whizlab1"; :-)


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inner class confusion