Upload
tana-booker
View
32
Download
2
Embed Size (px)
DESCRIPTION
Set & Get Method s. Prepared by: Afra`a S. Al- Shammari. Set & Get Methods. Set and Get methods are used to retrieve and modify the attributes of a class. And as your variables are private, they won't be accessible without these methods. Set Method (Setter). - PowerPoint PPT Presentation
Citation preview
SET & GET METHODS
•Prepared by: Afra`a S. Al-Shammari
2
SET & GET METHODS
Set and Get methods are used to
retrieve and modify the attributes of a
class. And as your variables are
private, they won't be accessible
without these methods.
3
SET METHOD(SETTER)
It is used to assign the values for the variables.
- Features:
Public.
Void (do not have a return type).
Hold attributes.
4
SET METHOD(SETTER)
Syntax:
Public Void setVariable( var type var name){this.var=var}
- Example: class A{ int x; Public void setX(int x){this.x = x;} }
5
GET METHOD(ACCESSOR)
It is used to retrieve the values of the variables.
- Features:
Public.
Have a return type.
Do not hold any attributes.
6
GET METHOD(ACCESSOR)
Syntax:
Public VarReturnType getVariable( ){return(var); }
- Example: class A{ int x; Public int getX(){return x;} }
7
You are appreciated