Inner Class , Nested Class , Static Class and Interfaces
interface A {//All implementation in Interface = Static
static class X{} //To Avoid : if(X instance of A) ,can be accessed as A.X
static abstract class Y{} //Not valid - Cannot instantiate abstract class (static)
static interface Z{} //Not valid - Cannot instantiate Interface (static)
}
abstract class B {
class X{} //X=private by default
abstract class Y{} //
interface Z{} //
}
class C {
void m(){class c{}}//Local inner class(visible only inside this method )
static class W{} //Accessed as C.W
class X{} //Nested Class
abstract class Y{} // Implementing class needs
interface Z{}
}
Nested Class:
1. Private by Default
2. Can access all the private members of super class
3. C face=new C();
C.X ear1=face.new X(); //logical grouping, readable and maintainable code
C.X ear2=face.new X();
4. Same operation can also be done using external classes
No comments:
Post a Comment