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

What is a prefix function.write down a code to compute prefix function.

544


What is an anonymous class in java?

552


What is set string?

599


Difference between a class and an object?

584


Why are variables important in research?

558






What does localhost mean?

502


What is difference between final and immutable?

565


What is the difference between jdk, jre, and jvm?

576


What is thread safe singleton?

521


Can we force the garbage collection to run?

540


How many types of interfaces are there?

578


What is data string?

503


What are the pillars of java?

491


What is class variable java?

589


Why is logger singleton?

564