0

Can anyone give me an example of multiple this statements in a class?

Can anyone give me an example of multiple this statements in a class?

18th Jun 2020, 12:26 PM
Ajoh Pv
Ajoh Pv - avatar
7 odpowiedzi
+ 3
Then let's take the second code example... public MyClass(int age, String name) { this.age = age; this.name = name; } public MyClass(String name) { this(0, name); } public MyClass(int age) { this(age, "unknown user"); } It's to avoid redundant code.
18th Jun 2020, 1:03 PM
Sandra Meyer
Sandra Meyer - avatar
+ 2
What do you describe as a 'this-statement'? public String getFullName() { return this.surname + " " + this.familyName; } or... public MyClass(int age, String name) { this.age = age; this.name = name; } or something different...?
18th Jun 2020, 12:38 PM
Sandra Meyer
Sandra Meyer - avatar
0
swim,multiple this statement means many this() statements in a single class,we use this() in a single class and super() in different classes
18th Jun 2020, 12:52 PM
Ajoh Pv
Ajoh Pv - avatar
0
Sandra Meyer,its not this keyword,its this() statement,like super statement
18th Jun 2020, 12:53 PM
Ajoh Pv
Ajoh Pv - avatar
0
this() without any parameters doesn't make sense from my point of view.
18th Jun 2020, 12:57 PM
Sandra Meyer
Sandra Meyer - avatar
0
Sandra meyer,I am just asking for a example of a program with this() statement,this() can include parameters
18th Jun 2020, 1:00 PM
Ajoh Pv
Ajoh Pv - avatar
0
Not synchronized... 🙃
18th Jun 2020, 1:04 PM
Sandra Meyer
Sandra Meyer - avatar