How to Use Non-static Member Class in Java


In this example we will show how to use non-static member class in Java.

Source Code

package com.beginner.examples;

public class MemberClassExample {
	 
    public class A{
        public void test(){
            System.out.println("It is a memeber class.");
        }
    }
    // get innner class 
    public A getInstance(){
        return this.new A();
    }
     
    public static void main(String[] args){
        MemberClassExample m = new MemberClassExample();
        A a = m.getInstance();
        a.test();
    }
}

Output:

It is a memeber class.
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments