+ 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.

2nd Sep 2017, 1:03 AM
Interstellar_Star
Interstellar_Star - avatar
4 Respostas
+ 7
Yes, you just override the objects toString() method. public String toString() { return this.attr1 + " " + this.attr2 + " " + etc; }
2nd Sep 2017, 1:06 AM
ChaoticDawg
ChaoticDawg - avatar
2nd Sep 2017, 1:12 AM
AgentSmith
+ 2
As ChaoticDawg said, you need to override the toString() method, and modify the code a little. Check this https://code.sololearn.com/c3tmkB4H2sv4
2nd Sep 2017, 1:16 AM
Salekin
Salekin - avatar
0
https://code.sololearn.com/cPWEJt84o54U/?ref=app
2nd Sep 2017, 1:21 AM
Ardu
Ardu - avatar