Date Class, Global variables, Constructor w/Parameters, Getters

Structure: Class > Datafields > Constructor > Getters

Global variable data-fields::

A time themed template. Date is the main class, followed by protected data-field variables of year, month, date that are distributed as individual copies for the rest of the objects. Note that a value must be assigned for each of these variables individually.

On the other hand, the following protected static final variable, I should say constant, MINYEAR is not like the other global variables. MINYEAR is static, so a single copy of this constant it is shared between all of the objects. MINYEAR is final, so the assigned integer value of 1583 cannot be changed during the runtime of the java program.


So followed by the class is the class’s constructor, also named Date. It contains the parameters newMonth, newDay, newYear. Notice that inside the constructor body that the newMonth value is passed on to the month, the newDay to the day, and the newYear to the year. This is to match the supposedly user inputted values newMonth, newDay, newYear as the actual global variables of month, day year.


Then comes the observer methods, or “getter” methods. They simply return the value of the variable specified (ie. return year returns the value of year). The key component is the return keyword that allows the java program to spit back out the specified value.


public class Date {
protected int year;
protected int month;
protected int day;
protected static final int MINYEAR = 1583;

public Date(int newMonth, int newDay, int newYear) {
// Initializes this Date with the parameter values
month = newMonth;
day = newDay;
year = newYear;

public int yearIs() {
// Returns the year value of this Date
return year;

public int monthIs() {
// Returns the month value of this Date
return month;

public int dayIs() {
// Returns the day value of this Date
return day;

What's Your Opinion?