Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8869831
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:34:29+00:00 2026-06-14T17:34:29+00:00

I am getting an error at public Rectangle(double width, double height){ saying that it’s

  • 0

I am getting an error at public Rectangle(double width, double height){ saying that it’s an invalid method declaration, return type required. I’m not sure how to fix it. These are also my instructions for my assignment:
Write a super class encapsulating a rectangle. A rectangle has two attributes representing the width and the height of the rectangle. It has methods returning the perimeter and the area of the rectangle. This class has a subclass, encapsulating a parallelepiped, or box. A parallelepiped has a rectangle as its base, and another attribute, its length. It has two methods that calculate and return its area and volume.

`public class Rectangle1
{

private double width;
private double height;

public Rectangle1(){
}

public Rectangle(double width, double height){
this.width = width;
this.height = height;

}

public double getWidth(){
return width;
}

public void setWidth(double width) {
this.width = width;

}


public double getHeight(){
return height;

}

public void setHeight(double height){
this.height = height;

}

public double getArea(){
return width * height;
}

public double getPerimeter(){
return 2 * (width + height);

}

}



public class TestRectangle {

public static void main(String[] args) {

Rectangle1 rectangle = new Rectangle1(2,4);

System.out.println("\nA rectangle " + rectangle.toString());
System.out.println("The area is " + rectangle.getArea());
System.out.println("The perimeter is " +
rectangle.getPerimeter());
}
}`
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:34:30+00:00Added an answer on June 14, 2026 at 5:34 pm

    Constructor name should be same as your class name. your class name is Rectangle1 thus your Constructor name should be the same as well, currently java compiler this it as an method without a return type, thus it complains.

    public Rectangle(double width, double height){
    

    should be

    public Rectangle1(double width, double height){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I keep getting an error saying that @android:style/Widget.Holo.Light.Button.Borderless is not public and so can't
I am running this code using oozie workflow and getting type mismatch error: public
I keep getting this error when I try to call Find() public void findTxt(string
I'm getting this error message with the code below: class Money { public: Money(float
I'm getting a strange error when I use F# to read a public readonly
I am getting a StackOverflow Error in this code: EDIT [XmlAttribute(ID)] public string ID
I am getting error saying: Object reference not set to an instance of an
I am getting error to convert T to Entity public T Add(T entity) {
I want to insert a word (public) inside parenthesis with sed keep getting error
I'm getting the error below and these are my classes. Shape class: public abstract

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.