Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

Why are inner classes required?

Answer Posted / qamrun nisa

when an inner class is defined it is a member of the outer
class in much the same way as other members like attributes,
methods and constructors. When we access private data
members of the outer class, the JDK compiler creates
package-access member functions in the outer class for the
inner class to access the private members. This leaves a
security hole.

In general we should avoid using inner classes. Use inner
class only when an inner class is only relevant in the
context of the outer class and/or inner class can be made
private so that only outer class can access it. Inner
classes are used primarily to implement helper classes like
Iterators, Comparators etc which are used in the
context of an outer class.

Is This Answer Correct ?    7 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

when to use ArrayList and when to use HashMap in webApplication.

4674


Can inner class be public in java?

997


Can we call the constructor of a class more than once for an object?

1076


Can a class have multiple subclasses?

1085


What are the string methods in java?

1067


What is variable explain with example?

1039


Differentiate between array list and vector in java.

1102


What is finalize()? Is finalize() similar to a destructor?

954


What is a jit compiler?

1110


Can we have two methods in a class with the same name?

1045


What is supplier in java?

992


What is the significance of java packages?

1095


How do I start learning java?

1051


Why does java have two ways to create child threads? Which way is better?

1027


What is cr keyboard?

1221