Create an Object for inner classes.
class ABC{
class XYZ{
private int x=10;
}
public static void main(String... args){
ABC.XYZ xx = new ABC().new XYZ();
System.out.println("Hello :: "+xx.x);
///Why is this allowed??
}}
The inner class is just a way to cleanly separate some functionality that really belongs to the original outer class. They are intended to be used when you have 2 requirements:
- Some piece of functionality in your outer class would be most clear if it was implemented in a separate class.
- Even though it's in a separate class, the functionality is very closely tied to way that the outer class works.
Comments
Post a Comment
Please post comments here:-)