Nested
Classes
In Java, just like methods,
variables of a class too can have another class as its member. Writing a class
within another is allowed in Java.
The class written within is called
the nested class, and the class that holds the inner class is called the
outer class.
class Outer
{
private class Inner
{
void dispaly()
{
System.out.println("this is inner class");
}
}
void call()
{
Inner obj=new Inner();
obj.dispaly();
}
}
class InnerDemo{
public static void main(String s[])
{
Outer ob=new Outer();
ob.call();
}
}
Example solve watch video for understanding
// inner class By Prakash Sonar
class outer
{
private class Inner
{
void display()
{
System.out.println("inner class method");
}
}
void Callinner()
{
Inner obj=new Inner();
obj.display();
}
}
class InnerDemo{
public static void main(String S[])
{
outer obj=new outer();
obj.Callinner();
}
}
Example solve watch video for understanding
// inner class By Prakash Sonar
class outer
{
private class Inner
{
void display()
{
System.out.println("inner class method");
}
}
void Callinner()
{
Inner obj=new Inner();
obj.display();
}
}
class InnerDemo{
public static void main(String S[])
{
outer obj=new outer();
obj.Callinner();
}
}
Comments