I have a class "circle" which extends from class "shapes". When I try to call the "display" method using the keyword "super"
return (super.display() + " Color: " + color);
the value for size gets lost. I think it calls this constructor, shapes()
How do I get the program to call this constructor, shapes(int size)
Here's my code:
class shapes {
private int size;
shapes(){}
shapes(int size){
this.size = size;
}
public String display() {
return ("Size: " + size);
}
}
class circle extends shapes {
private String color;
circle(String color){
this.color = color;
}
public String display() {
return (super.display() + " Color: " + color);
}
}
public class Main {
public static void main(String[] args) {
shapes shapes1= new shapes(123);
System.out.println(shapes1.display());
circle circle1 = new circle("red");
System.out.println(circle1.display());
}
}
=====================
Here's the output:
Size: 123
Size: 0 Color: red