I don't understand the difference between this | Sololearn: Learn to code for FREE!
Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite
+ 5

I don't understand the difference between this

e. g this.setAge=a; and this.setAge(a); // when can one use each of this

4th Sep 2017, 9:32 AM
Sampson Joshua (Jozy)
Sampson Joshua (Jozy) - avatar
5 Réponses
+ 1
this.age=a; // it's is intalization statement this.age(a);// it's is method calling statement
27th Sep 2017, 10:00 AM
GOWTHAMI BOJJA
GOWTHAMI BOJJA - avatar
+ 5
thanks alot @GOWTHAMI BOJJA now I get it clear with the last answer u gave. you made it simpler to understand it's actually a great Answer👏👏👏👏👏
27th Sep 2017, 10:12 AM
Sampson Joshua (Jozy)
Sampson Joshua (Jozy) - avatar
+ 2
You should use: This.Attribute = value; inside the class And objectRef.setAtribute(); when accessing the value from outside the class Here is why. This refers to the current object (a specific instance of the class you are writing the code in). However your issue actually concerns methods and properties. "=" is the assignment operator that means it is used to set the properties (attributes) of an object. However, it is common practice to restrict access to object properties by making them private and forcing access through a public set() or get() method (encapsulation). This means an outside user cannot directly access the property or its allocated memory..
4th Sep 2017, 10:41 AM
josh mizzi
josh mizzi - avatar
+ 1
this is a reference keyword which is used as to identify the current objects where it is required. and it is used in constructors to refer or call the another constructor with this (this keyword) like (this()) for default constructor.and it is used as only 1st statement of the constructor.
27th Sep 2017, 9:55 AM
GOWTHAMI BOJJA
GOWTHAMI BOJJA - avatar
0
tnqu
27th Sep 2017, 10:14 AM
GOWTHAMI BOJJA
GOWTHAMI BOJJA - avatar