---
title: "Can you achieve Runtime Polymorphism by data members in java?"  
description: "Can you achieve Runtime Polymorphism by data members in java?"  
author: "Samuel Fernandes"  
published: 2015-04-02  
updated: 2020-09-23  
canonical: https://www.mindstick.com/interview/2390/can-you-achieve-runtime-polymorphism-by-data-members-in-java  
category: "java"  
tags: ["java"]  
reading_time: 1 minute  

---

# Can you achieve Runtime Polymorphism by data members in java?

Method is overridden not the data members, so runtime polymorphism can't be achieved by data members.**Example:**Here in both the classes have a data member speedlimit, we are accessing the data member by the reference variable of Parent class which refers to the subclass object. Since we are accessing the data member which is not overridden, hence it will access the data member of Parent class always.

```
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  }
```

\
**Output:** 90

## Answers

### Answer by Anonymous User

Method is overridden not the data members, so runtime polymorphism can't be achieved by data members.**Example:**Here in both the classes have a data member speedlimit, we are accessing the data member by the reference variable of Parent class which refers to the subclass object. Since we are accessing the data member which is not overridden, hence it will access the data member of Parent class always.

```
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  }
```

\
**Output:** 90


---

Original Source: https://www.mindstick.com/interview/2390/can-you-achieve-runtime-polymorphism-by-data-members-in-java

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
