Nested Static Class and Nested Interface in Java

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Program 1

class First   //outer class
{
      static int n=100;
      static class Second  //inner
      {
            static void display(int x)
           {
               System.out.println("Second class : "+n);
               System.out.println("Parameter: "+x);
               System.out.println(x+n);
           }  
      }
}

class TestStaticNested
{
      public static void main(String args[])
      {
            //   First.Second fs=new First.Second();
            //    fs.display();
                   First.Second.display(500);
            
      }
}

Program 2

interface Testouter
{
      void display();
      interface TestInner
      {
           void show();
      }
}
class Test1 implements Testouter.TestInner
{
     public void show()
     {
          System.out.println("This is show method of TestInner Test 1 Class");
     }
}

class Test2 implements Testouter.TestInner
{
     public void show()
     {
          System.out.println("This is show method of TestInner in Test 2 class");
     }
}

class TestNestedInterface
{
   public static void main(String args[])
   {
      Testouter.TestInner T1=new Test2();
      T1.show();
   }

}

 

Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *