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
when to use ArrayList and when to use HashMap in webApplication.
Can inner class be public in java?
Can we call the constructor of a class more than once for an object?
Can a class have multiple subclasses?
What are the string methods in java?
What is variable explain with example?
Differentiate between array list and vector in java.
What is finalize()? Is finalize() similar to a destructor?
What is a jit compiler?
Can we have two methods in a class with the same name?
What is supplier in java?
What is the significance of java packages?
How do I start learning java?
Why does java have two ways to create child threads? Which way is better?
What is cr keyboard?