Reputation:
So I have to build some classes using this UML diagram.
I'm have trouble with Circle and Square.
I understand that Circle inherits from Ellipse, who inherits from Shape. I understand that when you use a subtype's constructor, the first line in the body should be super().
What I don't understand is how I'm supposed to do this with my diagram. I don't know where double r is going and I don't know how I can call super(x,y) when there is no constructor in Ellipse or Shape that take just those two parameters. Same idea with square.
I get constructor errors when I follow the UML exactly.
Upvotes: 1
Views: 3093
Reputation: 6314
Circle is an ellipse that has both focal points at the same location i.e it's defined by only one radius. So if your circle constructor is:
Circle(double x, double y, double r)
Your need to call the ellipse constructor with:
super(x, y, r, r)
The same with square and rectangle.
Upvotes: 2