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();

14th Jan 2018, 3:09 PM
Roman
Roman - avatar
1 ответ
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
14th Jan 2018, 3:30 PM
michal