0
Which part is still wrong?
public void Test{ String teks; public void Test (String s){ this.text =s; } public static void main (String[] args){ Test test = new Test ("ABC"); System.out.println (test); } }
5 Answers
+ 1
if you want to be able to print your object directly, you should override the toSting method, but in your case I think It's easier to print test.text.
by the way, you declared an attribut 'teks' but used 'text' in the constructor, a typo for sure.
+ 1
to override the toSting method look at Muhammad Bilal nice code.
or just do this:
System.out.println(test.text);
as text is a public attribut.
0
Constructor dont have any return type not even void.
0
What do you mean?