Java Class asSubclass() MethodThe asSubclass() method of java Class casts this Class object to represent a subclass of the class represented by the specified class object. It throws a ClassCastException if the cast is not valid otherwise it returns a reference to this(current) class object. SyntaxParameterU - Type to cast this class object to clazz - class of the type to cast this class object to. ReturnsThis Class object and cast to represent a subclass of the specified class object). ThrowsClassCastException Example 1Test it NowOutput: class ClassasSubclassExample1 class SubClass class ClassasSubclassExample1 Example 2Test it NowOutput: Derived Class Constructor........ class Class.ClassasSubclassExample2 class Class.SubClass1 class Class.SubClass1 Next TopicJava Class |
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India