GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  J2EE  >  OOPS
Go To First  |  Previous Question  |  Next Question 
 OOPS  |  Question 29 of 31    Print  
inner classes
What are advantages of inner class


  
Total Answers and Comments: 2 Last Update: September 14, 2009     Asked by: jrcheenu 
  
 Sponsored Links

 
 Best Rated Answer
Submitted by: ssalguti
 

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.



Above answer was rated as good by the following members:
getravi2k, talktoatish
April 25, 2008 15:37:47   #1  
ssalguti Member Since: April 2008   Contribution: 1    

RE: inner classes

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.


 
Is this answer useful? Yes | NoAnswer is useful 2   Answer is not useful 0Overall Rating: +2    
September 14, 2009 00:08:04   #2  
goksn Member Since: May 2009   Contribution: 94    

RE: inner classes
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.

 
Is this answer useful? Yes | No

 Related Questions

Latest Answer : By extending the abstract class by other class and creating object to that class ...
Tags : Abstract

What is the use of abstract classes? How will we decide in a scenario, whether we have to use abstract class or interface?
Read Answers (21) | Asked by : Rajiv
Tags : Abstract

Latest Answer : The class whose all methods have body is called as conceetclass Yes object class is concreet class ...
Read Answers (6) | Asked by : vishal

Class Outer{int a;Outer (){a=10;}public static void main(String args[]){final Outer o1=new Outer();Outer o2=new Outer();class inner{inner(){o1.a=20;//allowed//o2.a=30; not allowed}}}}Why inner classes can access only final variables as illustrated? Thanks in advance!

Most frequently used diagrams are- Class Diagram- Sequence DiagramRarely Used- Component Diagram- Package DiagramClass Diagram A diagram that shows a collection of declarative (static) model elements, 
Latest Answer : Class   Diagram  : They describe the static structure of a system.Package Diagram  : Package diagrams organize elements of a system into related groups to minimize dependencies between packages.Object  Diagram  : ...
Read Answers (1) | Asked by : sunils

What are advantages of inner class  
Latest Answer : 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 ...
Read Answers (2) | Asked by : jrcheenu


 Sponsored Links

 
Related Articles

ODP.NET - Fundamental ODP.NET Classes to Retrieve Data

ODP NET Fundamental ODP NET Classes to Retrieve Data To retrieve data from an Oracle database using ODP NET we need to work with a few of the ODP NET classes At this point we will discuss the most fundamental classes available in ODP NET for retrieving data mosgoogle The following is the list of fun
 

Microsoft AJAX Library - C# and JavaScript Classes

C and JavaScript Classes For the purpose of demonstrating a few more OOP related concepts we ll use another class Our new class is named Table and it has two public fields rows columns and one method getCellCount The getCellCount method should return the number of rows multiplied by the number of co
 

Microsoft AJAX Library - JavaScript Classes

JavaScript Classes Not only can JavaScript functions contain other functions but they can also be instantiated This makes JavaScript functions a good candidate for implementing the concept of a class from traditional object oriented programming This is very helpful feature indeed because JavaScript
 

OOPS Tutorials

Object oriented programming OOP is a computer science term used to characterize a programming language that began development in the 1960’ s The term object oriented programming’ was originally coined by Xerox PARC to designate a computer application that describes the methodol
 

C++ Storage Classes

C Storage Classes In this C tutorial you will learn about storage classes types of storage class variables Automatic External and Static explained with examples mosgoogle center Storage classes In the context of scope of variables in functions exists the important concept of storage class What is St
 

C++ Objects and Classes

C Objects and Classes An Overview about Objects and Classes In object oriented programming language C the data and functions procedures to manipulate the data are bundled together as a self contained unit called an object A class is an extended concept similar to that of structure in C programming l
 

The Interview Snafu

How to turn someone else’s mistake to your advantage Your dream job is about to become reality. A recruiter gave you the heads up about the perfect position at Humungous Conglomerate, Inc. You went through five interviews as well as a battery of psychological tests mandated by their HR de
 

Winning a Job Interview with a Winning Resume

Does your resume unlock your potential, take your skills to the highest level and win you the interview and the job you want now? The job market today is highly competitive and even if you think you have what it takes to get an interview you won’t get over the line without a polished, prof
 

Importance of Proper English during Job Interview

Importance of Proper English during Job Interview Your job interview is crucially important and it will determine whether or not you will get the job Depending on the type of job you re going for it is very important for you to use proper English In most cases jobs which offer higher salaries will h
 

HR Interview - HR Interview Mistakes You Will Want To Avoid

HR Interview Mistakes You Will Want To Avoid The job interview can be a stressful process This is especially true for those who are going after a competitive position Your nonverbal communication combined with the answers you give during the interview will determine if you are hired mosgoogle While
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape