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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T17:26:30+00:00 2026-06-01T17:26:30+00:00

I have been reading up on Java and oop design. One of the exercises

  • 0

I have been reading up on Java and oop design. One of the exercises was to design a system to hold astronomical objects and some basic attributes of them.

the system needs to hold Stars, Galaxies and Planets.

Each Object has a type, eg for stars; dwarf, giant and normal

Starts also have a colour.

So far I started with a abstract base class for all these objects called AstronomicalObject:

public abstract class AstronomicalObject {
  //Is this totally pointless?
}

I then made 3 classes Star, Galaxy and Planet that extend this class. For each type of these Objects I made additional subclasses ie DwarfStar that extends Star. Is this an acceptable idea? The additional classes feel slightly redundant:

public class DwarfStar extends Star{
  public final String SIZE = "DWARF";
  public DwarfStar(String colour) {
    super(colour);
  }
}

For the colour attributes I did this:

public class Star extends AstronomicalObject{
  public final static String YELLOW = "YELLOW";
  public final static String RED = "RED";
  public final static String WHITE = "WHITE";
  public final static String SIZE = "NORMAL";
  private String colour;

  public Star(String colour) {
    this.colour = colour;
  }

  public String getColour(){
    return this.colour;
  }
}

So to create a star object I would use:

DwarfStar ds = new DwarfStar(Star.YELLOW);

Unfortunately the book doesn’t have an answers page or discuss this exercise so I was wondering if my solution was valid oop design. Or if it could be improved upon?

  • 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-01T17:26:32+00:00Added an answer on June 1, 2026 at 5:26 pm

    Is this totally pointless?

    if your three objects have a type as you said, then no it isn’t useless as you will be able to write only one setter and getter in your superclass instead of implementing it in each subclass. In fact a superclass is not useless if every subclasses have a common property.

    Then for the colours you could use an Enum instead of static variables:

    public enum Colours{
        YELLOW, RED, WHITE, NORMAL
    }
    

    and access them with Colours.RED for example.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been doing some reading and have found out that the Java Swing
Recently I have been reading up on some of the flaws with the Java
I have been reading over some code lately and came across some lines such
I have been reading these slides about Java finalizers. In it, the author describes
I've been reading up on Java EE architecture, and have seen (in the Oracle
I have been reading Effective Java by Joshua Bloch and so far it really
I have been reading the descriptions of referencing in Java, and, while I feel
I have been reading the API and documentation ( http://java.sun.com/products/java-media/jai/forDevelopers/jai1_0_1guide-unc/Analysis.doc.html 9.5 Edge Detection) and
I've been reading Effective Java and decided to try to put some of what
I have been reading through the Java tutorial on RMI. I like the approach

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.