Java.lang Package Classes

Java Class - isMemberClass() Method

The java.lang.Class.isMemberClass() method returns true if and only if the underlying class is a member class.


public boolean isMemberClass()


No parameter is required.

Return Value

Returns true if and only if this class is a member class.




In the example below, the java.lang.Class.isMemberClass() method is used to check if the given class is a member class or not.

import java.lang.*;

public class MyClass {
  public static void main(String[] args) {
    MyClass x = new MyClass();
    Class cls = x.getClass();

    //print the name of the class
    String name = cls.getName();
    System.out.println("Class Name: " + name);

    //check if the class is a member class
    Boolean result = cls.isMemberClass();
    System.out.println("Is it MemberClass?: " + result);

The output of the above code will be:

Class Name: MyClass
Is it MemberClass?: false

❮ Java.lang - Class