+ 3
I dont understand this
Please help me to understand the "this" inside the () from this code Polymorphism obj = new Polymorphism(this);
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
+ 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
+ 3
AJ #Level 20 End Day okaay thank you so much!!
+ 2
I think it has something to do with structs or classes.
+ 2
"this" represent the current object
+ 2
~ swim ~ Thank you so much for the answer!!
+ 2
~ swim ~ oh thank you!!
+ 2
This inside the()means this obj
+ 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
+ 1
RinasSam Thank you so much for answering!
Do you know what is the difference if we dont write "this" inside the () ?
+ 1
Ome Where did you find this because I am getting error when doing like your example inside main method.
+ 1
AJ #Level 20 End Day this is my school assignment. It is inside a class not in main method
+ 1
click the link for get explanation of ' this ' keyword
https://www.google.com/amp/s/www.geeksforgeeks.org/this-reference-in-java/amp/
+ 1
This reference the current object
+ 1
Yes what do you need to do
+ 1
I remember that it represents an object in D.
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
0
AJ #Level 20 End Day i'm sorry :(, and dont know, but it works in my assignment.
0
Shaxzoda Sherzodovna thank you so much for answering!!
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