Compare and contrast abstract classes and interfaces. Why would you use an abstract class? Why would you use an interface?
What will be an ideal response?
An abstract class describes the general notion of what it means to be an object of that class. Abstract classes are incomplete—they normally contain data and one or more methods and properties that are declared abstract because they cannot be implemented in a general sense. Objects of an abstract class cannot be instantiated. Concrete derived classes must declare the “missing pieces”—the implementations of the abstract methods and properties that are appropriate for each specific derived class.
Abstract class references can refer to objects of any of the classes below the abstract class in an inheritance hierarchy and therefore can be used to process any such objects polymorphically. An interface also describes abstract functionality that can be implemented by objects of any number of classes. Classes that implement an interface can be completely unrelated, whereas concrete derived classes of the same abstract base class are all related to one other by way of a shared base class. An interface is often used when disparate (i.e., unrelated) classes need to provide common functionality (i.e., methods and properties). An interface can also be used in place of an abstract class when there are no default implementation details (i.e., method and property implementations and instance variables) to inherit. When a class implements an interface,
it establishes an is-a relationship with the interface type, just as a derived class participates in an is-a relationship with its base class. Therefore, interface references can be used to evoke polymorphic behavior, just as abstract base class references can.
You might also like to view...
After method EnsureCapacity doubles the StringBuilder instance’s current capacity, if the new capacity is still lower than the value that the programmer wishes to ensure:
a) EnsureCapacity doubles capacity again b) EnsureCapacity sets capacity to the requested number c) EnsureCapacity sets capacity to one more than the requested number d) None of the above
Stream method ________ eliminates duplicate objects in a stream.
a. distinct b. discrete c. unique d. different
Referring to the accompanying figure, which of the following links should be used to adjust display color quality?
A. What display settings should I choose B. Display C. Advanced settings D. Connect to the projector
________ lines are used to transfer the requested data from the hard drive to the computer
Fill in the blank(s) with correct word