+ 1
Minor help required!!
Hi, Please go through this code first: https://code.sololearn.com/cBGTsjd8oLNF/?ref=app i am wondering whether it is possible to just write something like System.out.println(A) ; instead of writing System.out.println(A.attribute1 + A.attribute2 + ...) ; to get the following output: car bmw series 5 the thing is... i tried it, but i didnt get any output(from this particular println). btw, i just started using sololearn yesterday, and i'm also pretty new to java programming. thank you.
4 odpowiedzi
+ 7
Yes, you just override the objects toString() method.
public String toString() {
return this.attr1 + " " + this.attr2 + " " + etc;
}
+ 4
As Chaotic said, here is an example:
https://stackoverflow.com/questions/1526826/printing-all-variables-value-from-a-class
+ 2
As ChaoticDawg said, you need to override the toString() method, and modify the code a little.
Check this
https://code.sololearn.com/c3tmkB4H2sv4
0
https://code.sololearn.com/cPWEJt84o54U/?ref=app