1 / 7

Set & Get Method s

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).

tana-booker
Download Presentation

Set & Get Method s

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 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 VoidsetVariable( 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 VarReturnTypegetVariable( ){ return(var); } - Example: • class A{ • int x; • Public intgetX(){return x;} • }

  7. You are appreciated

More Related