+ 3

I dont understand this

Please help me to understand the "this" inside the () from this code Polymorphism obj = new Polymorphism(this);

1st Apr 2020, 7:00 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
29 ответов
+ 4
Ome Here is a solution of your problem. It is only possible in case of polymorphism I think. Basically this refers to current object of the class B so it is possible when we create constructor of the another class A with the object of class B as a parameter. https://code.sololearn.com/cM8vEGmZj0ja/?ref=app
1st Apr 2020, 8:24 AM
A͢J
A͢J - avatar
+ 3
I don't think that we can make a constructor which has an object of the class as a parameter. See this example when I tried to do it gives me error. https://code.sololearn.com/ciAoDNfenpS9/?ref=app
1st Apr 2020, 8:10 AM
A͢J
A͢J - avatar
+ 3
AJ #Level 20 End Day okaay thank you so much!!
1st Apr 2020, 8:26 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
+ 2
I think it has something to do with structs or classes.
1st Apr 2020, 7:12 AM
RinasSam
RinasSam - avatar
+ 2
"this" represent the current object
1st Apr 2020, 7:30 AM
C0MM1T
C0MM1T - avatar
+ 2
~ swim ~ Thank you so much for the answer!!
1st Apr 2020, 8:03 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
+ 2
~ swim ~ oh thank you!!
1st Apr 2020, 8:18 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
+ 2
This inside the()means this obj
1st Apr 2020, 9:05 AM
Shaxzoda Sherzodovna
Shaxzoda Sherzodovna - avatar
+ 2
"this" normally represent the current object in the class . For instance on if you have two class which one class extends the other & let's say you creat a constructor which pass one parameter,now if you creat an object using the two class For the first object which is created by super class you pass the value bay "this" operator & For the second object which is created by the sub class you can pass the value by super operator
1st Apr 2020, 7:38 PM
Dawit Yitagesu
Dawit Yitagesu - avatar
+ 1
RinasSam Thank you so much for answering! Do you know what is the difference if we dont write "this" inside the () ?
1st Apr 2020, 7:13 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
+ 1
Ome Where did you find this because I am getting error when doing like your example inside main method.
1st Apr 2020, 7:37 AM
A͢J
A͢J - avatar
+ 1
AJ #Level 20 End Day this is my school assignment. It is inside a class not in main method
1st Apr 2020, 7:48 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
+ 1
click the link for get explanation of ' this ' keyword https://www.google.com/amp/s/www.geeksforgeeks.org/this-reference-in-java/amp/
1st Apr 2020, 1:21 PM
Aazad Waf 🌀
Aazad Waf 🌀 - avatar
+ 1
This reference the current object
1st Apr 2020, 1:36 PM
Santosh Singh
Santosh Singh - avatar
+ 1
Yes what do you need to do
3rd Apr 2020, 4:41 AM
Shaxzoda Sherzodovna
Shaxzoda Sherzodovna - avatar
+ 1
I remember that it represents an object in D.
3rd Apr 2020, 7:48 AM
RinasSam
RinasSam - avatar
0
C0MM1T Thank you so much for answering! Do you know what is the difference if we dont write "this" inside ()? Because i erase "this" inside () and its error
1st Apr 2020, 7:50 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
0
AJ #Level 20 End Day i'm sorry :(, and dont know, but it works in my assignment.
1st Apr 2020, 8:17 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
0
Shaxzoda Sherzodovna thank you so much for answering!!
1st Apr 2020, 10:57 AM
Putri Nabila Hapsari
Putri Nabila Hapsari - avatar
0
I inviting you to a scheduled Zoom meeting. Topic: Developers Lounge. Time: Apr 2, 2020 17:00CAT Africa/Lagos Join Zoom Meeting https://us04web.zoom.us/j/7093994115 Meeting ID: 709 399 4115 Lets have fun in this lock down and share ideas
2nd Apr 2020, 12:34 PM
Sam
Sam - avatar