Online Java Compiler By
JavaTpoint.com
package Class; public class ClassasSubclassExample2 { public static void main(String[] args) { ClassasSubclassExample2 class1 = new ClassasSubclassExample2(); SubClass1 subclass = new SubClass1(); Class obj = class1.getClass(); System.out.println(obj); // sub class SubClass1 Class obj2 = subclass.getClass(); System.out.println(obj2); Class xy = obj2.asSubclass(obj); System.out.println(xy); } } class SubClass1 extends ClassasSubclassExample2 { public SubClass1() { System.out.println("Derived Class Constructor........"); } }
Output