Writing an object value in java -
Writing an object value in java -
this question has reply here:
how create println/print method custom class 6 answershello have question little programme how can print value of p1? when using p1.tostring() method still shows me address of object searching in google other ways , still don't know how this. here code:
public class boss { string name; public boss(string input) { // constructor name = "our boss known : " + input; } public static void main(string args[]) { boss p1 = new boss("super-man"); system.out.println(p1.tostring()); }
you seem have forgotten override tostring()
// add together boss public string tostring() { homecoming name; } or (as have code),
// system.out.println(p1.tostring()); system.out.println(p1.name); you should add together getname() method boss well,
public string getname() { homecoming name; } java
Comments
Post a Comment