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); } }

8th Apr 2020, 8:08 AM
AliOta-Kun
AliOta-Kun - avatar
5 ответов
+ 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.
8th Apr 2020, 8:18 AM
John Robotane
John Robotane - avatar
8th Apr 2020, 8:24 AM
Muhammad Bilal
Muhammad Bilal - avatar
+ 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.
8th Apr 2020, 8:27 AM
John Robotane
John Robotane - avatar
0
Constructor dont have any return type not even void.
8th Apr 2020, 8:15 AM
Muhammad Bilal
Muhammad Bilal - avatar
0
What do you mean?
8th Apr 2020, 8:18 AM
AliOta-Kun
AliOta-Kun - avatar