Class vs. instance methods
instance methods
- methods that depend on instance state
- perform actions "on or for" object
- Queue q = new Queue();q.enqueue(1);
- q is an object; enqueue is an instance method
static methods
- methods that do NOT depend on instance state
- performs actions common to the entire class
- declared with keyword static
- double x = Math.sin(3.14159);
- Math is a class, so sin is a static method
- correct, but inefficient, is to instantiate a number object as:
- double x=(new Number(3.14159)).sin();