Q10 What is wring with this code?
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
import java.util.Date; public class WhatIsWrong { public static void main(String args[]) { Date date1 = new Date(); Date date2 = new Date(date1.getTime()); if(date1 == date2){ System.out.println("Dates match, so process it"); } } } |
A10. date1 == date2 only compares the references and not the actual dates. Since both the references are different objects, they will never be the same, and nothing will be printed. This…