Q q do not require an instance of the class and do

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: class, rather than part of an object. q༇  q༇  Do not require an instance of the class and do not understand the implicit parameter, this; therefore, cannot access an object's instance variables good for code related to a class but not to each object's state if public, can be called from inside or outside the class Example n༆  Static variables Classes can have static variables. Static variables are not replicated in each object; a single variable is shared by all objects of that class. private static type name; or, private static type name = value; q༇  Example: private static int count = 0; Assigning ids for BankAccount public class BankAccount { // static variable for assigning an account number // (shared among all instances of the class) private static int lastAssignedNumber = 1000; // instance variables(replicated for each object) private float balance; private int id; public BankAccount(float initial_balance) { lastAssignedNumber++; // advance the id id = lastAssignedNumber; // give number to account balance...
View Full Document

This note was uploaded on 02/10/2014 for the course CS 161 taught by Professor Boese during the Spring '08 term at Colorado State.

Ask a homework question - tutors are online