Hello. I'm working on a class hierarchy that starts with an abstract class called GeometricObject. I want to use this class to create classes of different types of triangles. I want to these classes to inherit the perimeter method from the Triangle class. Here's what I have so far.
abstract class GeometricObject
{
//signature for perimeter method
public abstract double perimeter();
public class Triangle extends GeometricObject
{
//explicit constructor
public Triangle(double s1, double s2, double s3)
{
this.side1=s1;
this.side2=s2;
this.side3=s3;
}//terminates constructor
//perimeter method
public double perimeter()
{
return side1+side2+side3;
}//terminates perimeter method
//local data fields
private double side1;
private double side2;
private double side3;
}//terminates text of class Triangle
public class Isosceles extends Triangle
{
//constructor
public Isosceles( double EQside, double otherside)
{
super(EQside, otherside);
}//terminates constructor
//local data fields
private double EQside;
private double otherside;
}//terminates class Isosceles
public class Equilateral extends Isosceles
{
//contructor
public Equilateral(double side)
{
super(side);
}//terminates constructor
//local data fields
private double side;
}//terminates class Equilateral
}//terminates class GeometricObject
I'm recieving the following error message:
F:\Java\GeometricObject.java:35: cannot reference this before supertype constructor has been called
super(EQside, otherside);
^
F:\Java\GeometricObject.java:46: cannot reference this before supertype constructor has been called
super(side);
^
There is obviously something wrong with the 2 lines starting with super, but I have not been able to figure it out.
Thanks to everyone in advance for any help.