-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathYear.java
More file actions
40 lines (35 loc) · 1.17 KB
/
Year.java
File metadata and controls
40 lines (35 loc) · 1.17 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/**
* Created: January 13, 2021
* Instructions: Create a class named Year that contains a data field that holds the number of days in a year.
* Include a get method that displays the number of days and a constructor that sets the number of days to 365.
*
* Create a subclass named LeapYear. LeapYear’s constructor overrides Year’s constructor and
* sets the number of days to 366.
*
* Write an application (Main class) that instantiates one object of each class and displays their data.
*/
public class Year {
public static void main(String args[]) {
Years year = new Years();
System.out.println("Number of Days in a year: " + year.getNumberOfDays());
LeapYear leap = new LeapYear();
System.out.println("Number of days in leap year: " + leap.getNumberOfDays());
}
}
class Years{
protected int numberOfDays;
public Years(){
this.numberOfDays = 365;
}
public int getNumberOfDays(){
return numberOfDays;
}
public void setNumberOfDays(int numberOfDays){
this.numberOfDays = numberOfDays;
}
}
class LeapYear extends Years{
public LeapYear(){
super.numberOfDays = 366;
}
}