0
Creating object by using superclass reference in java
Hi Could some please explain to me what a benefits of creating object by using superclass reference, if only object inheritance superclass fileds and methods? SuperClass obj = new SubClass();
1 Respuesta
0
you usually do not do this
you do SubClass obj=new SubClass()
then you can pass obj to a method which accepts SuperClass as argument, because it doesn't need specifically SubClass argument
void method(SuperClass p){}
in this method there is a variable p of type SuperClass, although it holds an instance of Subclass