refer to the following Date class declaration public class D
Solution
All are correct...
yes all options are correct
Here is code for testing. I have combined all the option and created code...
public class Date{
private int day;
private int month;
private int year;
public Date()
{
}
public Date(int m,int d,int y)
{
day = d;
month = m;
year = y;
}
public int month()
{
return month;
}
public int day()
{
return day;
}
public int year()
{
return year;
}
public String toString()
{
return month + \"/\"+day+\"/\"+year;
}
public static void main(String []args){
Date d = new Date(1,13,2002);
String s = d.toString(); // option 1
System.out.println(s);
int x = d.day(); // option 2
System.out.println(x);
Date e =d; // option 3
//Date e = new Date(1,13,2002); //comment the above line and uncomment this line option 4
int y = d.year; // option 5
System.out.println(y);
}
}
