Class Design: Accessor and Mutator Methods - PowerPoint PPT Presentation

1 / 5
About This Presentation
Title:

Class Design: Accessor and Mutator Methods

Description:

Class Design: Accessor and Mutator Methods. public int getAge() public ... Method Name. int x. Book b, Chapter chp, int numPages. Parameters. returning a value ... – PowerPoint PPT presentation

Number of Views:116
Avg rating:3.0/5.0
Slides: 6
Provided by: jacobh
Category:

less

Transcript and Presenter's Notes

Title: Class Design: Accessor and Mutator Methods


1
Class Design Accessor and Mutator Methods
  • public int getAge()
  • public void haveBirthday()
  • public void withdraw(double amt)

2
method signature
Access Modifier
Return type
Method Name
Parameters
public
String
getName()
add( )
public
void
int x
public
String
insert(
)
Book b, Chapter chp, int numPages
3
returning a value
  • public int sum(int x, int y)
  • return x y
  • public boolean verify sum(int x, int y, int sum)
  • return (x y) sum
  • public int getMax(int x, int y)
  • if (x gt y)
  • return x
  • return y

4
returning void
  • A return statement ends the method abruptly.
  • A return can be used to control the program flow.
  • public void verifyAcctBalance(Account acct,
    double balance)
  • if (acct.getBalance() balance)
  • return
  • else
  • acct.requestBalanceInvestigation(balance)
  • private void calcDayOfMonth()
  • dayOfMonth dayOfYear
  • if (dayOfMonth lt31 )
  • return
  • dayOfMonth - 31
  • if (!isLeapYear dayOfMonth lt 28)
  • return

5
Accessors and Mutators
  • Accessor method returns instance variable
    values.
  • Mutator method changes instance variable values.
Write a Comment
User Comments (0)
About PowerShow.com