7
SET & GET METHODS Prepared by: Afra`a S. Al-Shammari

Set & Get Method s

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

Page 1: Set & Get Method s

SET & GET METHODS

•Prepared by: Afra`a S. Al-Shammari

Page 2: Set & Get Method s

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.

Page 3: Set & Get Method s

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.

Page 4: Set & Get Method s

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;}    }

Page 5: Set & Get Method s

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.

Page 6: Set & Get Method s

6

GET METHOD(ACCESSOR)

Syntax:

Public VarReturnType getVariable( ){return(var); }

- Example: class A{ int x; Public int getX(){return x;} }

Page 7: Set & Get Method s

7

You are appreciated