Accessor method enables other element to set or get the value in a class .
Example :
Str myname(str _myname = myname)
{
myname =_myname;
return myname;
}
Example :
Str myname(str _myname = myname)
{
myname =_myname;
return myname;
}
In this example, It accepts a value as parameter and sets a class variable to this value and then returns the value. | |
The parameter has a default value set to the class variable value. So if the method is called without a parameter, it returns the value of the class variable. If it called with a value, then class variable is set to this value. |
No comments:
Post a Comment