java - how to add message to toString() in main method -
i have superclass, subclass , implementation class. overrode tostring in subclass, , have array in main method. question if have add together static variable subclass @ end, how should override tostring() in main method.
in super class,
public string tostring(){ homecoming "this message"; } in subclass,
private static int num; public string tostring(){ homecoming super.tostring()+ "\na message subclass"; }
in main method,
mysubclass myvariable=new mysubclass(); joptionpane.showmessagedialog(null,myvariable + "\nfinal message" + mysubclass.getnum()); this keeps giving me error message. tried,
string message = myvariable + "\nfinal message"; joptionpane.showmessagedialog(null,message); this didnt work either. should add together final message tostring()?
edit: need specify problem (is compile time error?)
if have superclass tostring , want in kid class append message on kid tostring(), override tostring() , phone call superclass method:
public class kid extends superclass { @override public tostring() { homecoming super.tostring() + " kid message"; } } now can phone call child.tostring() message
if not problem, please describe clearly.
java tostring superclass
No comments:
Post a Comment