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 7661923
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T13:40:21+00:00 2026-05-31T13:40:21+00:00

I had this original parent abstract class Geometric and i was extending it in

  • 0

I had this original parent abstract class Geometric and i was extending it in Octagon, and also implementing Comparable and Cloneable. IDK why i keep getting the above error.Help with be appreciated.

class Octagon extends GeometricObject implements Cloneable, Comparable{
  private double side;
  public class Octagon(){
  }
  public class Octagon(double s){
    side=s;
  }
  public double getArea(){
    return (2+4/Math.sqrt(2))*side*side;
  }
  public double getPerimeter(){
    return 8*side;
  }
  public int compareTo(Object o){
    if (getArea()>((Octagon)o).getArea()){
      return 1;
    }
    else if (getArea()<((Octagon)o).getArea()){
      return -1;
    }
    else 
      return 0;
  }
  public Object clone() throws CloneNotSupportedException{
    super.clone();
  }
}

And this is my Geometric Class

public abstract class GeometricObject{
  private String color="white";
  private boolean filled;
  private java.util.Date dateCreated;

  protected GeometricObject(){
    dateCreated=new java.util.Date();
  }

  protected GeometricObject(String color, boolean filled){
    dateCreated=new java.util.Date();
    this.color=color;
    this.filled=filled;
  }

  public String getColor(){
    return color;
  }
  public void setColor(String color){
    this.color=color;
  }
  public boolean isFilled(){
    return filled;
  }
  public void setFilled(boolean filled){
    this.filled=filled;
  }
  public java.util.Date getDateCreated(){
    return dateCreated;
  }
  public String toString() {
    return "created on "+dateCreated+"\ncolor: "+color;
  }
  public abstract double getArea();
  public abstract double 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-05-31T13:40:22+00:00Added an answer on May 31, 2026 at 1:40 pm

    Got it – the error is within you “constructors”:

    public class Octagon(){
    //     ^^^^^ <- remove
    }
    
    public class Octagon(double s){
    //     ^^^^^ <- remove
      side=s;
    }
    

    The class “modifiers” are illegal. Simply remove them.


    Bonus advice – consider changing the implementation of compareTo. You’re looking at the octagons area, which is perfectly OK for comparision. But it requires calculating the area each and every time when two octagons need to be compared.

    As the area only depends on the side value, it’s sufficient and much more efficient to compare octagons by their side length:

    public int compareTo(Object other) {
    
     if (!(other instanceof Octagon)) {
       throw new IllegalArgumentException("Comparision with other types is not supported");
     }
    
     Integer thisSide = side;    // autoboxing, legal conversion since Java 1.5
     Integer otherSide = ((Octagon) other).side;     
    
     // Easy trick: Integer is already comparable ;)
     return thisSide.compareTo(otherSide);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to convert an Application.cfc to script. The original had this: <cfcomponent displayname=Application
If I had this: var percentDiscount; function calculate(sale, original) { percentDiscount = Math.round(eval(((original-sale)/original) *
Had this working; at one stage. The problem is the following text is now
I had this problem before and can't for life of me remember how to
I had this nasty bug that disappeared in the past but now after quite
I had this doubt for sometime now, some people say that there's no such
I had this problem some time ago and I gave up but lately it
I had this error when I browse new web site that site sub from
I had this app using 1.9.2 and rails 3.2 and today I changed the
I had this working in an old code that I didn’t end up using...

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.