View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Case Final Project Summer 2007

Sum2003 Midterm Review: O-O Systems

1) a. Classes group definitions of attributes and services, provide reusable pieces, and act as a factory by producing new instances of themselves.

b. An instance is an object of a class.

2) Class methods are performed on the class while an instance method is performed on an object (aka instance) of a class.

3) There is only 1 class variable per class which all instances share the data inside that variable. Each instance has its own value for the instance variables of a class which only that instance can see/use.

4) new is a class method and initialize is an instance method.


I think some of those are kinda vague...so:

1. class - group of attributes and actions from which instances can me modeled.
instance - an occurance of a class, referred to as an object

2. class method can't change the particular attributes of the object doing the work (ie, class methods can't change values of the instance variables within that class).

3. class variable is an attribute whose value all occurances of that class share in common, instance variables' values may differ between objects of the same class.


1. A class is a collection of similar data and behavior which provides reusable pieces. You can also inherit from a class (from its attributes and services). Classes produce instances of themselves (instance creates an object). The class determines the data and behavior of its instances.

2. A class method is a message to the class (it's static) whereas an instance method is a message to the object, it can create more than one object. A class method can't work on object's data.

3. A class variable is something that all classes share. An instance variable is data that all instances of a class hold.

4. new is a class method and initialize is an instance method.

~Sabina Karkin


these all sound pretty good. here are some suggestions from various sources:

1. A class is a kind of template that describes the underlying structure of a group of objects. It specifies the variables and methods common to all objects of a certain kind. It could be said that a class is a blueprint, and an instance is a house. An object belonging to a class is called an instance of that class. If "Person" was a class, then [you] would be an instance of the class [Person]. People have attributes (hair color, height, name) which translate into variables and behaviors (say hello, stand up, sit down) which translate into methods.

2. a class method is a kind of method that operates on and affects the class as a whole as opposed to an instance method that operates on and only affects a specific object that is an "instance" of the class. as Sabina mentioned, class methods are also referred to as "static" methods.

3. similarly, a class variable is something that all instances of a certain class share, so it has the same value when accessed from any instance created of a certain class - all instances of a class share a single copy of a class variable. If one object changes the variable, it changes for all other objects of that type (class variables are sometimes called "static variables" ex. in Java). the value of an instance variable, however, is specific to each object - each instance of a class has its own copy of an instance variable.

An example of using a class variable and class method would be to keep track of how many instances of a class are created. Say you had a class "petDog" and you had a class variable "numberOfPetDogs." Each time the class method "new" is called you can increment this value. Then each dog created has access to this shared variable, and knows how many other competitors it has when racing to the food bowl in your kitchen...or something

4. i think everyone got this exactly right - new is a class method, initialize is an instance method :)

ellie harmon

Link to this Page