Sunday, 17 March 2019

Different Forms of Inheritance in Java

All objects eventually inherit from Object, which provides useful methods such as equals and toString.

 Subclass, Subtype and Substitutability

  1.  A subtype is a class that satisfies the principle of substitutability.
  2.  A subclass is something constructed using inheritance, whether or not it satisfies the principle of substitutability.
  3. Substitutability is fundamental to many of the powerful software development techniques in OOP.
  4. The idea is that, declared a variable in one type may hold the value of different type.
  5. Substitutability can occur through use of inheritance, whether using extends, or using implements keywords

Inheritance is used in a variety of way and for a variety of different
purposes .
  •  Inheritance for Specialization
  •  Inheritance for Specification
  •  Inheritance for Construction
  •  Inheritance for Extension
  •  Inheritance for Limitation
  • •Inheritance for Combination

One or many of these forms may occur in a single case.

In general we want to satisfy substitutability: if B is a subclass of A, anywhere we expect an instance of A we can use an instance of B.

Inheritance gets used for a number of purposes in typical object-oriented programming:

specialization -- the subclass is a special case of the parent class (e.g. Frame and CannonWorld)

specification -- the super class just specifies which methods should be available but doesn't give code. This is supported in java by interfaces and abstract methods.

construction -- the super class is just used to provide behavior, but instances of the subclass don't really act like the super class. Violates substitutability. Example: defining Stack as a subclass of Vector. This is not clean -- better to define Stack as having a field that holds a vector.

extension -- subclass adds new methods, and perhaps redefines inherited ones as well.

limitation -- the subclass restricts the inherited behavior. Violates substitutability. Example: defining Queue as a subclass of Dequeue.

combination -- multiple inheritance. Provided in part by implementing multiple interfaces.
 

0 comments :

Post a Comment

Note: only a member of this blog may post a comment.

Machine Learning

More

Advertisement

Java Tutorial

More

UGC NET CS TUTORIAL

MFCS
COA
PL-CG
DBMS
OPERATING SYSTEM
SOFTWARE ENG
DSA
TOC-CD
ARTIFICIAL INT

C Programming

More

Python Tutorial

More

Data Structures

More

computer Organization

More
Top