+ 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
5 Respostas
+ 1
this.age=a; // it's is intalization statement
this.age(a);// it's is method calling statement
+ 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👏👏👏👏👏
+ 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..
+ 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.
0
tnqu