Welcome To The World Of Java

This site will teach you the basics of Java. It is not necessary to have any prior programming experience.

Write a java program to print name of the current class and its super class name?

Somdeb Burman | 10:54:00 PM | 0 comments

class First {
 public static void main(String[] args) {
  String s = new String("HELLO");
  printSuperclass(s);
 }
 static void printSuperclass(Object s) {
  Class c = s.getClass();
  Class sc = c.getSuperclass();
  System.out.println("NAME OF CURRENT CLASS:"+ c.getName());
  System.out.println("NAME OF THE SUPER CLASS:"+ sc.getName());
 }
}


Output:

java First
NAME OF CURRENT CLASS : java.lang.String
NAME OF THE SUPER CLASS : java.lang.Object

Java Resources are available for Download from below

Category: , ,

0 comments