Write a java program to illustrate inner class accessing inner class properties

Write a java program to illustrate inner class accessing inner class properties

Program
class A
{
    int x=10;
    void f1()
    {
        System.out.println("this if f1 method");
    }  
    void f2()
    {
        B ob=new B();
        ob.f4();
    }
    class B
    {
        int y=30;
        void f3()
        {
            System.out.println("x="+x);
            f1();
        }
        void f4()
        {
            System.out.println("this is  f4 method");
        }
    };
    
    static class C
    {
        void f5()
        {
            System.out.println("this is f5 method");
        }
    }
};

public class Main 
{
    public static void main(String[] args)  
    {
        A oa=new A();
        oa.f2();
        A.B ob=new A().new B();// non static inner class object
        ob.f3();
        A.C oc=new A.C(); // static inner class object
        oc.f5();
            
    }
}

Output:

this is f4 method
x=10
this if f1 method
this is f5 method

Note: Outer class or external class cont be declare either static or final class.


Polymorphism In Java



More Questions


153 . Write a Java-program using dynamic method overridding
154 . Write a java program to illustrate inner class accessing inner class properties
155 . Write a package Program
156 . Write a package program using encapsulation
157 . Write a package program using data abstraction
158 . Write a package program using inheritance
159 . write a package program using polymorphism
160 . write a inner package program using polymorphism
161 . Write a program to handled the Arithmetic Exception
162 . Write a program to handled the InputMismatch Exception
163 . Write a program to handled the ArrayIndexOutOfBoundsException