Professional Documents
Culture Documents
Nested Class
Nested Class
----------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~NESTED
CLASS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
>> When we declare a named class inside another class, is known as a nested class.
Ques 1 :- what is a nested class exaplin all types of nested class with the help of
a example.
Ques 2 : What is the difference b/t normal class and ananomous class, explain with
the help of example.
Ques 3 : What is a ananomous class demostrate the concept with the help of a
programme.
>> INNER NESTED CLASS : It is the part of Non Static Nested class.
class outer
{
class inner
{
}
}
1. It will generate 2 byte code file i.e.
1) outer.class
2)
outer$inner.class
2. We can declare any static method or variable inside the inner class.
3. class outer{
void display()
{
SOP("Outer class method");
}
class inner{
void display()
{
SOP("Inner class method");
}
}
PSVM(String []args)
{
outer o=new outer();
o.display();
outer.inner i=o.new inner();
i.display();
}
}
4. Inner class can directly access any type of a variable of a outer class.
Syntax :
class outer{
//Outer class
Void display(){
//Method
class inner{
//Method local nested class
}
}
}
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ANONYMOUS
CLASS~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-----------------------------------------------------------------------------------
----------------------------------------------------------------------
--> Syntax :-
parent_class object=new parent_class()
{__________________
__________________
Lines of code
__________________
__________________
}; //Don't forget to put a
semicoloumn.
Ques :-
WAP for creating a 5 ananomous classes