Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

  ---Inner Class Concept in Java---


Using this concept we will create class inside class ,It is also called Nested Class:-

1 Dynamic Inner class:-

   It Contain Dynamic data member and member function.

  class A
 {
       class B
       {

      }


}

Example of Inner Class:-

class A
{
    class B
    {
         public void fun1()
         {
             System.out.println("B");
         }

    }
  public void fun()
         {
             System.out.println("A");
         }

public static void main(String args[])
{
     A obj = new A();
     obj.fun();
     obj.new B().fun1();
}

}
2 Static Inner Class:-

     It Contain Static Data member and member function.

   class A
 {
       static class B
       {

      }


}


Example of Static Inner Class in Java:-

class A
{
   static class B
    {
         public static void fun1()
         {
             System.out.println("B");
         }

    }
  public void fun()
         {
             System.out.println("A");
         }

public static void main(String args[])
{
     A obj = new A();
     obj.fun();
     A.B.fun1();
}

}

Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post