In this example, we may see how to initialise or call a static member class. Here is the method to create a static member class: TestClass.MemberClass m = new TestClass.MemberClass().
Source Code
package com.beginner.examples;
public class TestClass {
//This is a static member class
public static class MemberClass{
public void printStr(String str){
System.out.println(str);
}
}
public static void main(String[] args) {
//An object that creates a static member class
TestClass.MemberClass m = new TestClass.MemberClass();
//Call the method of this object
m.printStr("I love programming");
}
}
Output:
I love programming