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 testring () {...} Consider the implementation of a write () method that is added to the Date class:/* Write the date in the form m/d/y, for example 2/17/1948. */public void write () {/+ implementation code */} Which of the following could be used as/+ implementation code */I System.out.println(month + \"/\" + day + \"/\" + year); II System, out.printlnGionth () + \"/+ day () + \"/\" + year()); III System.out.println(this); I only II only III only II and III only I, II, and III
Solution
8)ans)E
Reason:
System.out.println(month+\"/\"+day+\"/\"+year);
As we are accessing the private variables in the same class method .we can get the required result with this statement.
System.out.println(month()+\"/\"+day()+\"/\"+year());
We can access the method of the current class with out any reference.so this is also correct way of displaying the output in the required format.
System.out.println(this);
This is also correct.because,\" this \" always refers to the current class.So if we write System.out.println(this); then internaly it will access the toString() method of Date class.As we have already the code to display the date in the required format ,it is also as correct way.
So all the three are correct.
