abstract class Shape{
final int b = 20;
public void display(){
System.out.println("This is display method");
}
abstract public void calculateArea();
}
class Rectangle extends Shape{
public static void main(String args[]){
Rectangle obj = new Rectangle();
obj.display();
//obj.b=200;
}
}
When I execute this code, it is outputting “This is display method” but in child class I create object for child class and call parent class method. Why is it invoking parent class method.
Thank you.
1)
bisfinalin parent class. You can’t change value. You will get compilation error here.2) Method
public void calculateArea()is absent in child class. You will get compilation error here also3) In your code, method
void display()isn’t overrided