Why are inner classes required?
Answers were Sorted based on User's Feedback
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 |
Answer / shubha patil
inner class is basically used for binding the one class into
another class.
| Is This Answer Correct ? | 0 Yes | 1 No |
Answer / mohammad aleemuddin
Inner classes are mainly used to encapsulate the data
| Is This Answer Correct ? | 1 Yes | 4 No |
What is Recursion Function?
What is the protocol is used in type4 driver?
What do you understand by java virtual machine?
What is a “stateless” protocol ?
Can you tell me range of byte?
Explain about anonymous inner classes in java?
Explain Global variables in Packages?
interface X{ void m1(); void m2(); } class Child2 extends Object implements X { public void m1(){ System.out.println("Child2 M1"); } public void m2(){ System.out.println("Child2 M2"); } } public class ParentChildInfterfaceDemo { public static void main(String[] args){ X x = new Child2(); X x1 = new Child2(); x.m1(); x.m2(); x.equals(x1); } } Will the above code work? If yes? Can you please explain why the code x.equals(x1) will work as the equals method is called on interface reference vaiable?
What is core java used for?
What is float in java?
What is the purpose of skeleton and stub?
AWT event listeners extends what interface?