refer to the following Date class declaration public class D

refer to the following Date class declaration: public class Date {private int day; private int month; private int year; public Date()//default constructor} ...} public Date(int no, int da, int yr)//constructor {...} public int nonth()//returns month of Date {...} public int day()//returns day of Date {...} public int year()//returns year of Date {...}//Returns String representation of Date as \"n/d/y\". e.g. 4/18/1985. public String toString() {...}} A client program creates a Date object as follows: Date d = new Dated, (1, 13, 2002); Which of the following subsequent code segments will cause an error? String s = d.toString(); int x = d.day(); Date e = d; Date e = new Dated, (1, 13, 2002); int y = d.year;

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);
}
}

 refer to the following Date class declaration: public class Date {private int day; private int month; private int year; public Date()//default constructor} ...

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site