, System.out.println(bob.cardValue); .
overriden toString() " (, , , java Object)
toString() - (bob.cardValue) - , (), (bob) (bob - , "":)).
toString(), :
System.out.println(bob);
System.out.println(bob.toString());
String bobInMyString = bob.toString();
String bobInMyStringUsingCasttoString = (String) bob;
Btw it should look like (annotation for the compiler):
@Override
public String toString()
{
String output =
"The" + rank + "of" + suit + "=" + cardValue + "\n";
return output;
}
}
If you ask why to use toString () override , see for example. for this very good example (complex numbers), it is useful for custom classes or for writing an object to a file, etc.
source
share