GeekInterview.com
Series: Subject: Topic:

Java OOPS Interview Questions

Showing Questions 1 - 1 of 1 Questions
Sort by: 
 | 

Inner classes

Asked By: jrcheenu | Asked On: Apr 23rd, 2008

What are advantages of inner class

Star Read Best Answer

Editorial / Best Answer

Answered by: ssalguti

View all answers by ssalguti

Member Since Apr-2008 | Answered On : Apr 25th, 2008

Logical grouping of classes—If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes their package more streamlined.

Increased encapsulation—Consider two top-level classes, A and B, where B needs access to members of A that would otherwise be declared private. By hiding class B within class A, A's members can be declared private and B can access them. In addition, B itself can be hidden from the outside world.

More readable, maintainable code—Nesting small classes within top-level classes places the code closer to where it is used.

Answered by: goksn on: Sep 14th, 2009

Defining a class within another class is known as nested class.

If class B is defined within class A, then B is known to A, but not outside of A.

Class B has access to the members, including private members of the Class A.

However,the class A does not have access to the members of Class B.

Answered by: ssalguti on: Apr 25th, 2008

Logical grouping of classes—If a class is useful to only one other class, then it is logical to embed it in that class and keep the two together. Nesting such "helper classes" makes th...

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.