+ 1

In java i create vehicle class and its object is v1 then i write a syntex System.out.println(v1); then output is

vehicle@2a139a55 what is this please explain me.

27th Feb 2017, 7:04 PM
niraj kamdar
niraj kamdar - avatar
2 ответов
+ 6
The implementation of the toString method in class Object returns a string matching this pattern: classname@objecthashcode. To get a useful output, you have to override the toString method in your class, e.g. @Override public String toString() { return name+" "+type; // just an example } Usually you return all attributes of your class from the overridden toString method, but you can return every string you want to.
27th Feb 2017, 7:26 PM
Tashi N
Tashi N - avatar
+ 3
you are printing an object (in your case v1). the result is a string returned by the method v1.ToString() this string is composed by the class name of the object, the @ sign and the unsigned hexadecimal representation of the hash code of the object http://docs.oracle.com/javase/7/docs/api/java/lang/Object.html#toString%28%29
27th Feb 2017, 7:27 PM
seamiki
seamiki - avatar