0

What does this output mean?

What does this value of p mean and what object/class this p is refering to? And does newly created object in the main method also contains variable string ? https://code.sololearn.com/cG52NX1X0343/?ref=app

7th Apr 2020, 8:58 PM
Sagar Gupta
Sagar Gupta - avatar
2 Answers
+ 1
According to your code, p is a reference variable pointing to an object of type Palak. You cannot directly print a reference variable like that. It will give you 'className@hashcode' of the object. In order to get a readable result, you have to override the toString() method inside class Palak.
7th Apr 2020, 9:30 PM
Avinesh
Avinesh - avatar
0
> And does newly created object in the main method also contains variable string ? Palak p = new Palak(10); p.pal = "value of pal"; System.out.println(p.pal);
8th Apr 2020, 12:29 AM
zemiak