What is the class "class" in Java?


The Java.lang.Class class instance represent classes and interfaces in a running Java application. It has no public constructor.

Example

Following is the example demonstrates the usage of the class Class.

The java.lang.Class.getCanonicalName() method returns the canonical name of the underlying class as defined by the Java Language Specification. It returns null if the class does not have a canonical name.

Live Demo

import java.lang.*;

public class ClassDemo {
   public static void main(String[] args) {
      ClassDemo c = new ClassDemo();
      Class cls = c.getClass();
      
      //Returns the canonical name of the underlying class if it exists
      System.out.println("Class = " + cls.getCanonicalName());
   }
}

Ouput

Class = com.tutorialspoint.ClassDemo

Updated on: 30-Jul-2019

341 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements