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