0

I read abstract classes cannot be instantiated.But I cant understand it without example. Can anyone explain this line?

abstract class Bike{     abstract void run();   }   class Honda4 extends Bike{   void run(){System.out.println("running safely");}   public static void main(String args[]){    Bike obj = new Honda4();  // here abstract class is instantiated  obj.run();   }   }  

8th Aug 2019, 5:50 AM
Geek
Geek - avatar
1 Resposta
+ 2
its not the abstract class to be instanced but a not abstract one (eg Honda4)... You can use abstact class reference (like "obj" reference in your code) for assign childs class instance to it (supposing than them are instanciables)
8th Aug 2019, 6:25 AM
KrOW
KrOW - avatar