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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T20:36:47+00:00 2026-05-31T20:36:47+00:00

Superclass source code public class Date { private int month; private int day; private

  • 0

Superclass source code

public class Date {
private int month; 
private int day; 
private int year; 


public Date() {
setMonth(1);
**day = 1;**
setYear(1900);
}

public Date(int month, int day, int year) {
this.setMonth(month);
this.**day** = day;
this.setYear(year);
}

Month and Year works fine because I can use the setMonth and setYear in my subclass. However, when I try to use day it says the var is not visible because its private. There is no setter for day in the superclass but there is a getter. What should the setter look like? Furthermore, what should my subclass contructor look like?

Subclass contructor

public EDate(int month, int day, int year) 
{

this.setMonth(month);
day = getDay();
this.setYear(year);
}

Subclass Day setter

public void setDay(int newInt) {
if (isGooddDate(getMonth(), newInt, getYear())==true)
{    
newInt = this.getDay();
}

Any help is much appreciated!

  • 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-31T20:36:48+00:00Added an answer on May 31, 2026 at 8:36 pm

    I dont think there is a need to subclass your Date class in the first place. The reason is because the Date functionality will remain same, no matter what happens. So no need for the subclass constructor.

    And as far as date setter goes, you are going in the right direction:

    public void setDate(int dateValue) {
        if(isDateValid(dateValue)) {
            date = dateValue;
        } else {
            throw new Exception("Invalid date");
        }
    }
    

    If your class features time support you could actually write a better solution. Convert the date value in time, no matter what the date is. While storing, convert the time into an appropriate date. This is how built-in DateTime class works.

    for example: if you store 2006-16-80 it will be stored as 2007-06-19 rather than throwing an exception. Just a thought!

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

Sidebar

Related Questions

I have the following code: class SuperClass { public static String getName() { return
I have an abstract superclass DataContent: public abstract class DataContent { [Key(), DatabaseGenerated(DatabaseGeneratedOption.Identity)] public
I have the following: public class MyClass : SuperClass { [JsonProperty] public virtual string
I have an AbstractEntity class as superclass for all my entites that defines an
I have this object which is an instance of a superclass. I want to
I've attached the Android source code via File > Project Structure > Modules >
Editable is an interface, the code as follows is a method of EditText class,
I have a superclass Person, which contains the following method: public String getClasHierarchy() {
Is it at all possible to override a private method of a super class
I have: @interface SuperClass : UIViewController <UITableViewDelegate,UITableViewDataSource> And then @interface SubClass : SuperClass This

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.