I have 2 classes Class A & Class B where Class A extends Class B
Now in the constructor of Class A , I have
Class A(Integer integerParam){
B superclass = new B(integerParam);
}
and the constructor of Class B is as
Class B(Integer integerParam) {
System.out.println(integerParam);
}
In addition to this I have a few methods in Class B as follows
public void ClassBMethod(){
System.out.println(integerParam);
}
I want to use reflection to invoke the Super Class method ClassBMethod, and I create an Instance of the Super class to do so like this
Class superClazz = Class.forName(classInstance.getClass().getSuperclass().getName());
Constructor superClassconstructor = superClazz.getConstructor(new Class[]{Integer.class});
Object superclassInstance = superClassconstructor.newInstance(integerParam);
The problem is here the instance of the Super class is getting created twice, once through the Class A constructor and second on reflection.
How can I call the avoid this and call the Super class method without creating the instance