6. What is difference between anonymous inner class and general class?
- A general class can extend only one class at a time of course inner class can extend only one class at a Time.
- A general class can implement any no of interfaces at a time but a anonymous inner class can
- implement only one interface at a time
- A general class can extend a class and can implement an interface simultaneously but an
7. What is difference between normal inner class and static nested class?
Normal Inner Class |
Static Nested Class |
- Inner class object always associated with outer class object ie without existing outer class object there is no chance of existing inner class object.
|
- Nested class object never associated with
outer class object , ie without existing outer class object inner class object can exist |
- Inside normal inner class we cant declare static members.
|
- Inside static nested class can
declare static members |
- We cant place main method in normal inner class and hence innocation of inner class directly from command prompt is not possible.
|
- We can place main method in static nested class and hence innocation of nested class directly from command prompt is possible
|
- From normal inner class we can access both static and non static members of outer class.
|
- From static nested class we can access only static member of outer class
|
8.What is static nested calss?why the term nested instead of inner in static nested class?
Some times we can declare inner class with static modifier such type of inner class are called static
nested classes.the term nested instead of static because without existing outer class object inner
class object can exist.
Example
Class outer{
Static class Nested{
Public static void main(String[] args){
System.out.println(“nested class main()”);
}
}
Public static void main(String[] args){
System.out.println(“outer class main()”);
}
}
9. Inside inner class is it possible to declare main()?
No it is not possible to declare main () inside inner class but in static nested class it is possible for
Example refer above code