Download - Nested and Enum Type in Java
![Page 1: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/1.jpg)
1 Prepared By: Prof. Ashish Bhatia
Nested TypeFor Semester – III [MCA]August 2012
Prepared byProf. Ashish [email protected]@asbspace.inwww.asbspace.in
Prepared Using
![Page 2: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/2.jpg)
2 Prepared By: Prof. Ashish Bhatia
Note● This ppt is for teaching purpose only.
● The ppt may contain some material from
books/api documentation/internet.
● No intention of breaking any rights or what so
ever.
![Page 3: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/3.jpg)
3 Prepared By: Prof. Ashish Bhatia
Nested Classes● The class define inside another class are
known as Nested Class.
● Top Level Nested Class● Inner class is static
● Inner Class
● Local Class
● Anonymous Class
![Page 4: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/4.jpg)
4 Prepared By: Prof. Ashish Bhatia
Why we need nested class?● Logical Grouping of class
● Helper classes
● Increase encapuslation
●
![Page 5: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/5.jpg)
5 Prepared By: Prof. Ashish Bhatia
Top Level Nested Class● Static member class is also known as top level
nested class.
● Member class and enclosing class shares trust
replationship in that they can access each
other memebers, including private members.
![Page 6: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/6.jpg)
6 Prepared By: Prof. Ashish Bhatia
![Page 7: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/7.jpg)
7 Prepared By: Prof. Ashish Bhatia
Inner Classes● Non-static member classes.
● Relationship : ● We cannot have an instance of innerclass without
having instance of the outer class.
● Used to represent one to many relationship.
● Eg : Account Class [Outer]and Transaction
class[Inner]● We cannot have transaction without Account
● Inner class cannot have static members.
![Page 8: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/8.jpg)
8 Prepared By: Prof. Ashish Bhatia
![Page 9: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/9.jpg)
9 Prepared By: Prof. Ashish Bhatia
Local Class● Class inside a method, constructor or intializer
block.
● This class donot have access specifier and
cannot be dcelared static / non-static.
![Page 10: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/10.jpg)
10 Prepared By: Prof. Ashish Bhatia
![Page 11: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/11.jpg)
11 Prepared By: Prof. Ashish Bhatia
Anonymous Class● Do not have name.
● Defined and created at same place.
● Become part of expression.
● Single inheritance type either extend or
implement
● Always non-abstract.
![Page 12: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/12.jpg)
12 Prepared By: Prof. Ashish Bhatia
enum Type● Java 5 onwards.
● Cannot have super class but can implement
interface.
● Number of instances are fixed.
● ; required after declaration.
● Sub class of Enum
● Instances have name and ordinal value.
![Page 13: Nested and Enum Type in Java](https://reader037.vdocument.in/reader037/viewer/2022100304/554a4e3eb4c905572f8b4669/html5/thumbnails/13.jpg)
13 Prepared By: Prof. Ashish Bhatia
enum Type
● Each instance are static and final.● Ordinal Value starts from 0 ● To access Month.January ● Enum type are comparable [ ordinal]● Values and Valuesof ● public static Month[] values()● public static Month valueOf(String n)