Inner Classes:A class within another class is called inner class
code without inner classes is more maintainable and readable.when you access private data members of the outer class,the JDK comploier creates package-access member functions in the outer class for the inner class to access the private members.This Leaves a 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 amde privatge so that only outer class can acess it. Inner classes are used primarly to implement helper classes like iterators,comparators etc. when are used in the context of an outer class.
You can use public access specifier befor a class
code without inner classes is more maintainable and readable.when you access private data members of the outer class,the JDK comploier creates package-access member functions in the outer class for the inner class to access the private members.This Leaves a 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 amde privatge so that only outer class can acess it. Inner classes are used primarly to implement helper classes like iterators,comparators etc. when are used in the context of an outer class.
You can use public access specifier befor a class
- you can use public access specifier before a class
- you cannot use private access specifier before a class
- only inner classes can be declare a the private
- Directly you cannot create objects to the inner class
- we can create objects to the outer classes
- inner classes objects can be created only its outer class.
- outer class is acting as a firewall.
- Annonymous Classes
- Static Inner Classes
- Non-Static Inner Classes
- Method-local Inner Classes
0 comments:
Post a Comment