typesreferences - Types and referencing components of an...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
Types and referencing components of an object A class name like Patient is also considered to be a type. Its values are the names of manila folders, or ob- jects, of that class. The type has no operations, because one shouldn’t be able to operate on these names, much like you can’t change the address of your house or apartment. Since Patient is a type, just as one can declare variables of type int , one can declare variables of type Pa- tient. Calling methods Suppose variable p contains the name a0 of an object. In this situation, in Java, one can call method get- Name of the object using (1) the name of the variable, (2) a period, (3) the function name, and (4) parentheses: p.getName() For example, we could use this call in an assignment statement to store the name “Jack Smith” in a variable s: S= p.getName(); In the same way, we can call procedure deposit using a statement that consists of (1) the name of the vari- able, (2) a period, (3) the name of the procedure, (4) parentheses with an argument between them —the amount to be deposited—, and (5) a semicolon:
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 07/07/2008 for the course CS 101 taught by Professor Gries during the Spring '08 term at Cornell University (Engineering School).

Page1 / 2

typesreferences - Types and referencing components of an...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online