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

class First {
 public static void main(String[] args) {
  String s = new String("HELLO");
 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());


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

No comments:

Post a Comment