0 votes
in JAVA by
Can you achieve Runtime Polymorphism by data members?

1 Answer

0 votes
by
No, because method overriding is used to achieve runtime polymorphism and data members cannot be overridden. We can override the member functions but not the data members. Consider the example given below.

class Bike{  

 int speedlimit=90;  

}  

class Honda3 extends Bike{  

 int speedlimit=150;  

 public static void main(String args[]){  

  Bike obj=new Honda3();  

  System.out.println(obj.speedlimit);//90  

   }  

Test it Now

Result:

90
...