java - Why does the Date class object prints today's date instead of reference of Date class -


when create object, object have reference of data members , methods of class.

 eg: testobject obj = new testobject();          system.out.println("test object is:"+obj); 

as per knowledge, new operator is, creates/ allocates memory blocks specified class(variables , methods) , assigns reference left hand variable (obj). so, above print statement prints reference of testobject class.

but, question is, when create object date class , print object, prints today's date.

 eg: date date = new date();          system.out.println("date object is:"+date); 

the above code prints today's date. why , how printing date instead of date class reference. please me.

am sorry, if silly question. silly, don't have answer question.

brief explanation appreciable.

when use reference of instance print, internally, it's called tostring() method of class. in date class, tostring() method return whatever date contains.

date api's tostring() methods says,

converts date object string of form:  dow mon dd hh:mm:ss zzz yyyy 

if override tostring() method in class meaningfully, whatever return printed instead of reference memory value.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -