Back to Top

Sunday, 29 January 2012

JAVA: Nested Class

 The class which is defined within another class is called nested class.
It can be divided into 2 types. They are -   static nested class & non-static nested class


Static Nested Class: 
  • Nested class which is declared static is static nested class.
  • Its methods & variables are associated with is mother/outer class.
  • It can be used only through object reference.
  • It is accessed using enclosing class name. Example: MotherClass.StaticNestedClass
  • It interacts with enclosing class or other class like any other top-level class.



Non-Static Nested Class/Inner Class:
  • It has access to the other members of the mother class, even they are private.
  • It can't define any static member itself.
  • Instance of inner class only valid within the instance of the enclosed class, & has direct access to the methods & fields of the enclosing instance.
  • To instantiate innerclass, 1st we need to instantiate the mother class. Example:
MotherClass.InnerClass iObj = MotherObject.new InnerClass();
 
Types of Inner Class
1.                 Local Inner Class 
2.                 Anonymous Inner Class 
 
Local Inner Class: 
·         The inner class which is declared within the body of a method is known as local inner class
·         It is not a member the enclosing class, hence doesn’t have any access specifies.
·         It has access to all the members of the enclosing class, even any final variable 
          within the scope.
 
Anonymous Inner Class:
·         The inner class which is declared within the body of a method and has no name 
          is known as anonymous inner class.
·         It is accessible only at the point of its declaration.

21 Responses to “ JAVA: Nested Class ”

Anonymous said...
29 January 2012 at 18:53

dis blog site is gettin betuh day by day....d best nested class expltion i've seen so far.thnx admin


Anijit Sarkar said...
5 March 2012 at 02:02

Thanks a lot!! :)


nivatha said...
29 August 2018 at 15:29

Great post! I am actually getting ready to across this information, It’s very helpful for this blog.Also great with all of the valuable information you have Keep up the good work you are doing well.
Devops training in Chennai
Devops training in Bangalore
Devops training in Pune
Devops Online training
Devops training in Pune
Devops training in Bangalore
Devops training in tambaram


simbu said...
7 September 2018 at 13:20

This is my 1st visit to your web... But I'm so impressed with your content. Good Job!


java training in chennai | java training in bangalore

java online training | java training in pune

selenium training in chennai

selenium training in bangalore


simbu said...
7 September 2018 at 13:20

Well you use a hard way for publishing, you could find much easier one!

java training in annanagar | java training in chennai

java training in marathahalli | java training in btm layout

java training in rajaji nagar | java training in jayanagar



ganga pragya said...
12 September 2018 at 17:57

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.

angularjs Training in bangalore

angularjs Training in btm

angularjs Training in electronic-city

angularjs Training in online


ganga pragya said...
12 September 2018 at 17:58

Very nice post here and thanks for it .I always like and such a super contents of these post.Excellent and very cool idea and great content of different kinds of the valuable information's.

angularjs Training in bangalore

angularjs Training in btm

angularjs Training in electronic-city

angularjs Training in online


SAM THOMAS CHRIST said...
3 October 2018 at 12:25

Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.


AWS Training in Rajaji Nagar | Amazon Web Services Training in Rajaji Nagar


Amazon Web Services Training in Pune | Best AWS Training in Pune

AWS Online Training | Online AWS Certification Course - Gangboard


SAM THOMAS CHRIST said...
3 October 2018 at 12:25

Hello! This is my first visit to your blog! We are a team of volunteers and starting a new initiative in a community in the same niche. Your blog provided us useful information to work on. You have done an outstanding job.


AWS Training in Rajaji Nagar | Amazon Web Services Training in Rajaji Nagar


Amazon Web Services Training in Pune | Best AWS Training in Pune

AWS Online Training | Online AWS Certification Course - Gangboard


Mounika said...
4 October 2018 at 11:17

I really like the dear information you offer in your articles. I’m able to bookmark your site and show the kids check out up here generally. Im fairly positive theyre likely to be informed a great deal of new stuff here than anyone
python training in chennai
python training in Bangalore
Python training institute in chennai


shethal said...
6 October 2018 at 16:14

Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.

Devops Training in pune
DevOps online Training


Unknown said...
9 November 2018 at 15:35

Good Post! Thank you so much for sharing this useful post, keep sharing!
DevOps Online Training


Venkatesh CS said...
29 May 2019 at 11:42

Thanks for sharing this post, really this is helpful for me.
Java Training in Chennai


oveiya said...
4 June 2019 at 17:53

You got an extremely helpful website I actually have been here reading for regarding an hour. I’m an initiate and your success is incredibly a lot of a concept on behalf of me.
dotnet online training


Chris Hemsworth said...
16 July 2019 at 11:58

The above article "JAVA: Nested Class" is so informative. This is more helpful for our
Learn best software testing online certification course class in chennai with placement
Best selenium testing online course training in chennai
Best online software testing training course institute in chennai with placement
Thanks for sharing.


divi said...
3 September 2019 at 12:12

thanks for it i really got more information thanks for sharing keep updating web design company in velachery


gautham said...
29 October 2019 at 10:24

this is the best post blockchain online training


cloudbeginners said...
6 September 2021 at 20:49

UGC Net Commerce


Professional Course said...
12 April 2022 at 12:48

Some really good points you wrote here ... Great things ... I think you raised some really interesting points. Keep up the good work.

Best Data Analytics Courses in Bangalore


iteducationcentre said...
12 September 2023 at 12:28

great article. Thanks for sharing.
Java Classes in Nagpur


k21academy said...
24 April 2024 at 23:22

Powerful paris dedicated server offering blazing speed, robust security, and 24/7 support for your online ventures. Elevate your server experience!


Post a Comment

Popular Posts

Subscribe via Email
Subscribe Java Interview Questions via Email
All Rights Reserved JAVA INTERVIEW QUESTIONS | Privacy Policy | Anijit Sarkar