Thursday, April 22, 2010

inheritance, polymorphism,interface

Inheritance
●Benefits of Inheritance in OOP : Reusability–Once a behavior (method) is defined in a superclass, that behavior is automatically inherited by all subclasses. –Thus, you can encode a method only once and they can be used by all subclasses. –A subclass only needs to implement the differences between itself and the parent.

●In Java, all classes, including the classes that make up the Java API, are subclassed from the Object superclass.
●Superclass–Any class above a specific class in the class hierarchy.
●Subclass–Any class below a specific class in the class hierarchy.
●Superclass–Any class above a specific class in the class hierarchy.
●Subclass–Any class below a specific class in the class hierarchy.

Polymorphism
●Polymorphism–The ability of a reference variable to change behavior according to what object it is holding.–This allows multiple objects of different subclasses to be treated as objects of a single superclass, while automatically selecting the proper methods to apply to a particular object based on the subclass it belongs to.

Abstract Classes
●Abstract class –a class that cannot be instantiated. –often appears at the top of an object-oriented programming class hierarchy, defining the broad types of actions possible with objects of all subclasses of the class

An interface –is a special kind of block containing method signatures (and possibly constants) only. –defines the signatures of a set of methods, without the body. –defines a standard and public way of specifying the behavior of classes. –allows classes, regardless of their locations in the class hierarchy, to implement common behaviors. –NOTE: interfaces exhibit polymorphism as well, since program may call an interface method, and the proper version of that method will be executed depending on the type of object passed to the interface method call.

No comments:

Post a Comment