Home » Java programming language

Java Class class isLocalClass() method with example

Class class isLocalClass() method: Here, we are going to learn about the isLocalClass() method of Class class with its syntax and example.
Submitted by Preeti Jain, on November 02, 2019

Class class isLocalClass() method

  • isLocalClass() method is available in java.lang package.
  • isLocalClass() method is used to check whether the underlying class is a local class or not.
  • isLocalClass() method is a non-static method, it is accessible with the class object only and if we try to access the method with the class name then we will get an error.
  • isLocalClass() method does not throw an exception at the time of checking the Class is declared as a local class or not.

Syntax:

    public boolean isLocalClass();

Parameter(s):

  • It does not accept any parameter.

Return value:

The return type of this method is boolean, it returns a boolean value based on the following cases,

  • It returns true, when this Class is a local class.
  • It returns false, when this Class is not a local class.

Example:

// Java program to demonstrate the example 
// of boolean isLocalClass() method of Class 

public class IsLocalClassOfClass {
    public static void main(String[] args) {
        // Create and Return String class
        String str = new String();
        Class cl1 = str.getClass();

        // Create and Return IsLocalClassOfClass class
        IsLocalClassOfClass lc = new IsLocalClassOfClass();
        Class cl2 = lc.getClass();

        // We are checking the class is a Local class
        boolean b1 = cl1.isLocalClass();
        boolean b2 = cl2.isLocalClass();

        System.out.print("Is" + " " + cl1.getSimpleName() + " ");
        System.out.println("Local class" + ": " + b1);

        System.out.print("Is" + " " + cl2.getSimpleName() + " ");
        System.out.println("Local class" + ": " + b2);
    }
}

Output

Is String Local class: false
Is IsLocalClassOfClass Local class: false


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.