28 Ağustos 2010 Cumartesi

Object Oriented Programming: Inheritance - Superclasses and Subclasses

Often, an object of one class is an object of another class as well. For example, in geometry, a rectangle is a quadrilateral ( as a squares, parallelograms and trapezoids).Thus, in java, class Rectangle can be said to inherit from class Quadrilateral. In this content, class Quadrilateral is a superclass and class Rectangle is a subclass. A rectangle is a specific type of quadrilateral, but it is incorrect to claim that every quadrilateral is a rectangle. The quadrilateral could be a parallelogram or some other shape. Note that  superclasses tend to be "more general" and subclasses "more specific".

Because every subclass object is an object of its superclass, and one superclass can have many subclasses, the set of objects represented by a superclass is typically larger than the set of objects represented by any of its subclasses. For example, the superclass Vehicle  represents all vehicles, including cars, trucks, boats, bicycles and so on. By constrant, subclass Car represents a smaller, more specific subset of vehicles. List the several simple examples of superclass and subclasses.
  • Student         -> GraduateStudent, UndergraudateStudent
  • Shape           -> Circle, Triangle, Rectangle
  • Loan             -> CarLoan, HomeImprovementLoan, MorgageLoan
  • Employee      -> Faculty, Staff
  • Bankaccount -> CheckingAccount, SavingAccount

Hiç yorum yok:

Yorum Gönder