CIT-73 Home http://www.c-jump.com/CIT73/CIT73syllabus.htm
Objects hide attributes and implementation-specific behaviors.
What's left exposed to the world is the public interface.
Details hidden inside the object is called encapsulation.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//A Very Simple Example class MainDriver { public static void main(String[] args) { System.out.println("The area is: "); Circle circle = new Circle(5); Rectangle rectangle = new Rectangle(4, 5); System.out.println( getArea( circle ) + getArea( rectangle ) ); } static double getArea( Shape shape ) { return shape.getArea(); } }
Any Shape-derived object we pass to getArea( ) java method of the MainDriver program will behave differently.
It depends on the type of shape which we pass as the parameter.
Composition means that an object is built from other objects.
Encapsulation means data hiding inside objects.
Inheritance relationship is considered an is-a relationship.
Composition relationship is termed a has-a relationship.
Inheritance is a process of deriving one class of objects from another class of objects.
Thus benefit of inheritance is reuse of existing code.
Derived class inherits attributes and operations from the base class.
Base class often called superclass.
Derived class often called subclass.
Link to this video on YouTube: