+ 1
class and object
SuperClass s=new SubClass(); actually what is happening when this code runs. and what is the need to create an instance of subclass using the super class
1 ответ
+ 2
You are creating a instance of SubClass and typecasting it to the SuperClass. It remains a SubClass instance and could be used as such. However, the main reason for this is having a second subclass both implementing different actions for the super class method.
For example, calling speak of the super class language would end up speaking French or Spanish in the corresponding subclass.