The program below is the answer to Deitel’s Java How to Program (9th Edition) Chapter 3 Exercise 3.15.

Question: Create a class called Date that includes three instance variables — a month (type int), a day (type int) and a year (type int). Provide a constructor that initializes the three instance variables and assumes that the values provided are correct. Provide a set and a get method for each instance variable. Provide a method displayDate that displays the month, day and year separated by forward slashes (/). Write a test application named DateTest that demonstrates class Date’s capabilities.

To run the application save both files with the same name as the class (because it is a public class) and with the .java file extension (in this case and Then compile both classes and run DateTest. Date will not run because it does not have a main method.

To compile both classes at the same time using the command prompt, use the command



To run DateTest, use the command

java DateTest

Below is Class to test Class

Click here to see other answers to Java How to Program.

1 Comment

Write A Comment