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.

Syntax

public boolean isMemberClass()

Parameters

No parameter is required.

Return Value

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

Exception

NA.

Example:

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