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 that are declared abstract because the methods cannot be implemented in
a general sense. Abstract classes can contain implemented methods. Objects of an ab- stract class cannot be instantiated. Subclasses must declare the “missing pieces”—im- plementations of the abstract methods that are appropriate for each specific subclass. 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 imple- mented by objects of any number of classes. Classes that implement an interface can be unrelated, whereas concrete subclasses of the same abstract superclass are all related to one other by way of a shared superclass. An interface is often used when disparate (i.e., unrelated) classes need to provide common functionality (i.e., methods) or use common constants. An interface can also be used in place of an abstract class when there are no default implementation details (i.e., method implementations and in- stance variables) to inherit. When a class implements an interface, it establishes an is- a relationship with the interface type, just as a subclass participates in an is-a relation- ship with its superclass. Therefore, interface references can be used to evoke polymor- phic behavior, just as an abstract superclass reference can.
You might also like to view...
The default folder on your hard drive that most often displays to access files through Microsoft applications is the ________ folder
A) Documents B) Default C) User D) Microsoft
Encryption is more than simple password protection—it will digitally obscure information to make it unreadable without a proper key to decode it
Indicate whether the statement is true or false
Which of the following can prevent social engineering?
A. Caller id B. Only give your password to special people C. Watch out for shoulder surfers D. all of the above
The constructors of a derived class can (directly) initialize only the (public data) members inherited from the base class of the derived class.
Answer the following statement true (T) or false (F)