Take the 2-minute tour ×

Superclass source code

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

public Date() {
**day = 1;**

this.**day** = day;


Subclass contructor

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

day = getDay();

Subclass Day setter

public void setDay(int newInt) {
newInt = this.getDay();

Any help is much appreciated!

share|improve this question
There are some differences between OO languages. Which one are you using? –  Eric J. Mar 22 '12 at 23:36
Thanks for the quick response. I'm using Java. –  Megatron Mar 22 '12 at 23:43

1 Answer 1

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!

share|improve this answer

Your Answer


