Online Java Compiler By
JavaTpoint.com
class Base { public Base() { System.out.println("Class Base "); } } class Derived extends Base { public static void Derived2() { System.out.println("Class Derived "); } } public class ClassasCastExample2 { public static void main(String[] args) { ClassasCastExample2 class1 = new ClassasCastExample2(); Class obj = class1.getClass(); System.out.println(obj); Base obj1 = new Base(); Derived obj2 = new Derived(); Object obbj = Base.class.cast(obj1); System.out.println(obj1.getClass()); System.out.println(obj2.getClass()); System.out.println(obbj.getClass()); } }
Output