Nested or Inner Class in Java

 Nested or Inner Class in Java



PROGRAM:



class Mobile
{
    class Sim {

        String SimName="Jio";

        String getName()
        {
            return SimName;
        }
    }
    class App
    {
        String AppName="MyJio";

        String getName()
        {
            return AppName;
        }
    }
}
public class InnerClass {

    public static void main(String args[])
    {
        Mobile mobile =new Mobile();

        Mobile.Sim sim= mobile.new Sim();

        Mobile.App app=mobile.new App();

        System.out.println("sim name is "+sim.getName());
        System.out.println("app name is "+app.getName());
    }
   
}

/*
OUTPUT

sim name is Jio
app name is MyJio

*/

Comments

Popular posts from this blog

PROGRAM TO FIND FACTORIAL OF A NUMBER USING RECURSION

PROGRAM TO FIND THE COUNT OF PARTICULAR NUMBER IN AN ARRAY

TELEPHONE BOOK USING HASHMAP