Online Java Compiler By
JavaTpoint.com
import java.lang.*; public class ClassasSubclassExample1 extends SubClass { public static void main(String[] args) { try { ClassasSubclassExample1 class1 = new ClassasSubclassExample1(); SubClass subclass = new SubClass(); // class ClassasSubclassExample1 Class obj = class1.getClass(); System.out.println(obj); // sub class SubClass1 Class obj2 = subclass.getClass(); System.out.println(obj2); Class xy = obj.asSubclass(obj2); System.out.println(xy); } catch(ClassCastException e) { System.out.println(e.toString()); } } } class SubClass { // sub class }
Output