ch10 - Polymorphism Enables you to “program in the...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Polymorphism Enables you to “program in the general” rather than “program in the specific.” Polymorphism enables you to write programs that process objects that share the same superclass as if they’re all objects of the superclass; this can simplify programming. Abstract classes Sometimes it’s useful to declare classes for which you never intend to create objects. Used only as superclasses in inheritance hierarchies, so they are sometimes called abstract superclasses . Cannot be used to instantiate objects—abstract classes are incomplete. Subclasses must declare the “missing pieces” to become “concrete” classes, from which you can instantiate objects; otherwise, these subclasses, too, will be abstract. An abstract class provides a superclass from which other classes can inherit and thus share a common design. Classes that can be used to instantiate objects are called concrete classes . Such classes provide implementations of every method they declare (some of the implementations can be inherited). Abstract superclasses are too general to create real objects—they specify only what is common among subclasses. Concrete classes provide the specifics that make it reasonable to instantiate objects. Not all hierarchies contain abstract classes. Programmers often write client code that uses only abstract superclass types to reduce client code’s dependencies on a range of subclass types. You can write a method with a parameter of an abstract superclass type. When called, such a method can receive an object of any concrete class that directly or indirectly extends the superclass specified as the parameter’s type....
View Full Document

{[ snackBarMessage ]}

Page1 / 18

ch10 - Polymorphism Enables you to “program in the...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online