posted 17 years ago
Encapsulation is the equivalent of data hiding. You protect your instance variables (your data), and control access through setter and getter methods. You also mark instance variables as being private. In Java, we don't expose our privates.
Inheritance is a mechanism used to represent an is-a relationship between objects. So, a Square is-a special Rectangle, and a Rectangle is-a special type of Shape, and a Shape is-a type of Object.
Polymorphism says any time you need an object, and instance of that object, or instance of a more specific type will do. So, if I need a Shape, a square will do. If I need a Rectangle, a Rectangle or a Square will do. Note that polymorphism is unidirectional, so if you need a Shape, a Rectangle will do, but if you need a Square, a rectangle will not suffice.
Those are very brief answers to a very broad set of questions.
Cheers!
-Cameron McKenzie