The other questions I have seen are about intentionally referencing a superclass constructor method and failing. I am not referencing a constructor yet; just trying to extend a class.
I am creating the class Square.java, which extends Rectangle.java.
Square.java is the subclass of Rectangle.java.
Interface.java
-Abstract.java - abstract class Abstract implements Interface.java
--Rectangle.java - public class Rectangle extends Abstract
---Square.java - public class Square extends Rectangle.
When compiling Square.java, I received the error message.
Square.java:3: error: constructor Rectangle in class Rectangle cannot be applied to given types;
public class Square extends Rectangle {
^
required: String,String,String,double,double
found: no arguments
reason: actual and formal argument lists differ in length
1 error
The content of Square.java is
public class Square extends Rectangle {
//no code is in the body
}
The constructor method of rectangle is:
public Rectangle (String t,String n, String c, double w, double h ){
width = w;
height = h;
color = c;
name = n;
type = t;
};
I want to create Square.java. Within this file, I would like to modify the Rectangle constructor method. But for right now, I just want the file to compile.
I have tried
- Copying the Rectangle constructor method into Square.java. That resulted in the same error message.
- Copying in the Rectangle constructor method and changing the name of the constructor method to Square. This resulted in the same error message.
- Commenting out the Rectangle constructor method within Rectangle.java. Square.java compiled without a problem. But... I need the Rectangle constructor in Rectangle.java.
- Creating a new Square constructor method and ran into more errors. Eventually, I want the Square constructor method to be a modified Rectangle constructor method.
From my understanding, constructor methods are not passed on to subclasses. I have not written code to intentionally reference the Rectangle constructor.
I am getting the feeling that the compiler is interpreting "... extends Rectangle { " as an attempt to reference the constructor instead of the class. I have run out of ideas on how to resolve this.
Thank you for any help.