Then we define a Student class implementing the person interface. In the above programming example, an interface Person is defined with a lone method ‘display ()’. ("Superclass of Student Class: " + superClass.getName()) declare class Student that implements Person The below example demonstrates the getSuperClass() method. Similarly, it provides a method getModifier() that returns the access modifier of the class. provides a method “getSuperClass()” that is used to get the superclass of any class. Then using this object we called the “getClass ()” method to get an object obj_test of. In the first line, we created an object of Test class. GetClass() method uses object of a class to get the object.įor example, consider the following piece of code: Test obj = new Test () Class obj_test = obj.getClass () Then we can use the obj_test to perform reflection as this object will have all the information about the class Test.įorName () method takes the name of the class as an argument and returns the Class object.įor example, the object of the Test class can be created as follows: class obj_test = Class.forName (“Test”) class extension.įor example, if Test is a class, then we can create a Class object as follows: Class obj_test = Test.class The first option to create an object of Class is by using the. We can create objects of using one of the following options.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |