• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can we define a class in a constructor of another class

 
Ranch Hand
Posts: 339
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can we define a class in a constructor of another class?Please give me some explanation also?I have found a question regarding this in a mock exam and it mention that it is possible.
 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes you can define a class inside a constructor. As constructor is also a method you can define
a) Method local inner class.
b) Annonymous Inner lass
Both the above type of class can access the memebers of the Outer class as these are considered as memebers of the outer class.
You cannot declare nested static class inside a method. As the only modifiers that are applicable for a method local inner class are abstract and final.
This is show below
 
reply
    Bookmark Topic Watch Topic
  • New Topic