Please explain in great detail how you have come to your solution. Thank you :-)
ID: 2247538 • Letter: P
Question
Please explain in great detail how you have come to your solution. Thank you :-)
Which statement is correct about the "a" and "b" after running following lines of code? Date a = new Date(12, 31, 1999): Date b = new Date(1, 1, 2011): b = a: Just programmer can free the memory of the second Date object a and b refer to different memory locations but each location contains equal objects the second Date object is orphaned object but it is still accessible Java garbage collection will remove the second Date objectExplanation / Answer
Code:
import java.io.*;
import java.util.*;
public class DateTest{
public static void main(String args[]){
System.out.println("hello Date");
try{
Date a=new Date(12,31,1999);
Date b=new Date(1,1,2011);
b=a;
System.out.println("Dates==="+b);
System.out.println("Dates==="+a);
}catch(Exception e){
System.out.println("except---"+e);
}
}
}
Output:
hello Date
Dates===Tue Jan 20 00:00:00 UTC 1920
Dates===Tue Jan 20 00:00:00 UTC 1920
So option 3 is correct because b object is override the a object and places a object value but still b is accessible