您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes
Introduction
Content
Apply
Reflect
Extend
previous.gif
 (3087 bytes)
next.gif
 (2959 bytes)

 
 
Content Index
Content Page # 15

Methods in general

Methods define what a class can do, or can have done to it. For example, a Mortgage class may have the following methods: 

  • deduct payment 
  • calculate interest 
  • foreclose 
  • etc. 
Note that it is not very clear which of these methods the class 慸oes? and which are 慸one to?it (i.e. change the state of the object). This is often the case, and modern practice is not to worry too much about this. 

In Java, all program instructions must be inside methods. Methods can read and change the values of instance variables as well as their own (local) variables.

Important points about methods include:

  • Each method must have an identifier (name)
  • Methods optionally have 
  • arguments (慽nputs?
  • a return value (憃utput? (see later this unit)
  • Normally the only way that an object of one class can change the variables of another is by invoking its access methods
Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright © 1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg