OUTER CLASS-JAVA

Develop a JAVA program to create an outer class with a function display. Create another class inside the outer class named inner with a function called display and call the two functions in the main class.

Note:

Your main method is inside the InnerClassDemo class:

So you need to run InnerClassDemo, not Outer.

PROGRAM:

package jo;

         class Outer{

       String so = "This is Outer Class";

       void display()

       {

       System.out.println(so);

       }

       void test(){

       Inner obj2 = new Inner();

       obj2.display();

       }

       //this is an inner class

       class Inner{

       String si ="This is inner Class";

       void display(){

       System.out.println(si);

       }

       }

       }

       class InnerClassDemo{

       public static void main(String args[]){

       Outer obj1 = new Outer();

       obj1.display();

       obj1.test();

       }

       }

 

OUTPUT:







No comments:

Post a Comment