1. what are the four types of inner classes
    • Inner classes
    • Methid Local Inner classes
    • Anonymous inner classes
    • Static nexted classes
  2. What is the relationship between an inner and an outer class?
  3. The inner class gets access to the members of the outer class as if they were the members of the outer class. It has access to the private members of the outer class. A regular inner class is one which is not static, method-local and anonylous inner class.
  4. How can you access a inner class.
  5. Through an instance of an outer class and not directly. The inner class is a member of the outer class and hence can access the methods of the outer class.
  6. How do you create an instance an inner class?
  7. YOU need to have an instance of an outer class.
  8. Eg of an regular inner classs.
    • public class MyOuter{
    • private int x;
  9. public void makeInner(){
  10. Inner in = new Inner();
    • in.seeOuter();
    • }
  11. class Inner{
  12. void seeOuter(){
    • System.out.prinln("x="+x);
    • }
    • }
    • }
  13. Why is Inner object created from a method is correct.
  14. because we have the outer object in the method through this.
  15. How do you create inner class object from ouside the outer class instance code.
  16. Myouter.MyInner inner = new MyOUter().new MyInner();
  17. Inside the inner class "this" refers to which class?
  18. to the inner class
  19. How do you get access to the Outer class's this?
  20. Using MyOuter.this
  21. What is method local inner class?
  22. Defining a class instead a method. And after the method closes creating an object of the inner class to access the details of inner class. A method local inner class can be instantiated only inside a method.
  23. can the method local inner class object have access to the local variables of the methods?
  24. No. Unless they are marked final. Because the local variables of the method live in a stack and they are blown away once the method is done. But that is nto the case for method local Inner class object it lives in a heap and it might still survive.
  25. what are the only modifiers that you can apply to method local inner class?
  26. abstract and final and not togther.
Card Set
Inner Classes