• Post Reply Bookmark Topic Watch Topic
  • New Topic

regarding DateFormat and calender  RSS feed

 
Santhi Bharath
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
while i am printing the objects of DateFormat and Calendar objects,i got something surprising like this

java.text.SimpleDateFormat@ce9bf0a5 -- for DateFormat

java.util.GregorianCalendar[all fields of Calender .....] -- for Calender


why we are getting sub class names instead of Calender and DateFormat?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16059
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's because class SimpleDateFormat does not override the toString() method from class Object, and class GregorianCalendar does.

If you print an object with System.out.println(...), then toString() will be called on the object to get a printable string.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!