• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner class confusion

 
sarvesh dikonda
Ranch Hand
Posts: 58
Firefox Browser Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


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
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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"; :-)


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic