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
What does the ‘static’ keyword mean? Is it possible to override private or static method in java?
How many decimal digits is 64 bit?
Can a class with private constructor be extended?
What are static initalizers in java ?
What is an array length?
What are the major advantages of internal iteration over external iteration?
What is http client in java?
What are streams in java 8?
What is navigable map in java?
What is the output of the below java program?
Is empty in java?
Is java call by value?
What are the types of strings?
What is stringjoiner ?
Why are there no global variables in java?