Java Program to Represent the Class in Different Ways

Java program to represent the class in different ways

// Java program to represent the class in 
// different ways

public class Main {
  public static void main(String[] args) throws ClassNotFoundException {
    Class cls1 = Class.forName("java.lang.String");
    Class cls2 = String.class;
    Class cls3 = int.class;

    System.out.println("Class represented by cls1: " + cls1);
    System.out.println("Class represented by cls2: " + cls2);
    System.out.println("Class represented by cls3: " + cls3);
  }
}

Output

Class represented by cls1: class java.lang.String
Class represented by cls2: class java.lang.String
Class represented by cls3: int
Share on:

Hi, I'm Ranjith a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Comment