Java Reference
In-Depth Information
Display 4.11 Overloading Method Names (part 1 of 2)
1
import java.util.Scanner;
2 public class DateSixthTry
3{
4
private String month;
5
private int day;
6
private int year; //a four digit number.
7
public void setDate( int monthInt, int day, int year)
8
{
9
if (dateOK(monthInt, day, year))
10
{
11
this .month = monthString(monthInt);
12
this .day = day;
13
this .year = year;
There are three different
methods named setDate .
14
}
15
else
16
{
17
System.out.println("Fatal Error");
18
System.exit(0);
19
}
20
}
21
public void setDate(String monthString, int day, int year)
22
{
23
if (dateOK(monthString, day, year))
24
{
25
this .month = monthString;
26
this .day = day;
27
this .year = year;
28
}
29
else
30
{
31
System.out.println("Fatal Error");
32
System.exit(0);
33
}
34
}
35
public void setDate( int year)
Two different methods
named setDate.
36
{
37
setDate(1, 1, year);
38
}
(continued)
 
Search WWH ::




Custom Search