• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Date question

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the below code the Answer is B. My question is why didnt the year for d1 changed to 2000 like it did for d2?


Which one or more of the following correctly describe the behavior when this program is compiled and run?

a) compilation is successful and the output is:
d1 is Fri December 31 00:00:00 GMT 1999
d2 is Fri December 31 00:00:00 GMT 1999

b) compilation is successful and the output is:
d1 is Fri December 31 00:00:00 GMT 1999
d2 is Sun December 31 00:00:00 GMT 2000

c) compilation is successful and the output is:
d1 is Sun December 31 00:00:00 GMT 2000
d2 is Sun December 31 00:00:00 GMT 2000

d) the assignment 'd1 = d2' is rejected by the compiler because the Date class cannot overload the operator '='.

e) the expression (d1 is " + d1 + "\nd2 is " + d2) is rejected by the compiler because the Date class cannot overload the operator '+'.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Within public static void method(Date d1, Date d2), di and d2 are "local" to their method(). Regardless if you assign d1 = d2 inside the method, outside the method, the "real" d1 is still pointing at the original object.

If you rename public static void method(Date d1, Date d2) to public static void method(Date x, Date y) it might clear it up visually and make more sense to you.

Hope this helps.
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please QuoteYourSources
 
reply
    Bookmark Topic Watch Topic
  • New Topic