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(); } }
1 ответ
+ 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)