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

Discussion 4 - James "Ben" Mitchell

Problem 1 from Midterm #1 Review - Spring 2004

1. What's a class? What's an instance?
A class is the definition of a type of object in an object-oriented system (for instance, a class could define a Corvette). An instance is one particular copy of an object (following my previous example, an instance would be one particular Corvette).

2. What's the difference between a class and instance method?
A class method is something that exists as a single entity used by all instances of a class. Each instance does not have its own "copy" of the method, and its effects are universal instead of only affecting one instance. (In Java, this would be a static method.) An instance method is a method that exists independently for each instance of a class.

3. What's the difference between a class and instance variable?
A class variable is much like a class method: only one copy exists for all instances of a class. For instance, you might have a class variable that holds the number of instances of the class. Each class would increment and decrement the variable when instantiated and destroyed respectively, and since it's shared between all copies, it would actually hold the number of instances. An instance variable is unique to an instance and is not shared with all instances. If the example of an instance count used an instance variable instead of a class variable, each instance would have its own independent count of instances; each would see only one instance, itself, since no other instance could access the variable.

4. In the following Squeak code what type of method (class or instance) is "new" and what type is "initialize"?
joe := Box new initialize

"new" is a class method, and "initialize" is an instance method.

Links to this Page