oop: Polymorphism, interfaces and Operator Overloading ch. 12
Which is used to specify that a class will be implementing an interface?
:
Which statement best describes the relationship between base class and derived class types?
A derived class reference can be assigned to a base class variable, but a base class reference cannot be assigned to a derived class variable
For which of the following would polymorphism not provide a clean solution?
A program to compute a 5% savings account interest for a variety of clients.
A class that implements an interface but does not declare all of the interface's methods must be declared:
Abstract
Which of the following characteristics can be used to create an interface for a file, a cat and a house?
Age
Which of the following is false about interfaces
An interface describes a set of methods that can be called on an object, providing a default implementation for the methods
Which of the following does not complete the sentence correctly? An Interface______
Can be instantiated
If an application needs to perform a derived-class-specific operation on a derived class object reference by a base class variable, the application must first cast the base class reference to a derived class reference through a technique known as _________.
Down casting
Polymorphism allows for specifics to be dealt with during:
Execution
A class that implements an interface may not act as a base class for other classes.
False
All methods in an abstract class are inherently abstract.
False
An abstract class cannot have instance data and non-abstract methods.
False
An interface can not provide properties with get and set accessors.
False
An interface is used when there's a default implementation to inherit.
False
Attempting to instantiate an object of an abstract class is a logic error.
False
Declaring an interface protected allows for extra security precautions.
False
If a class leaves one method in an interface undeclared, the class is implicitly declared by C# as an abstract class.
False
Objects of abstract base classes can be instantiated.
False
Polymorphism allows the addition of classes providing they were at least considered during program development.
False
The abstract keyword has the same effect as the virtual keyword.
False
The major drawback to polymorphically designed programs is that they do not take into account the future addition or deletion of classes.
False
The programmer may define implementations for abstract methods to act as a default.
False
Unfortunately, polymorphic programs make it difficult to add new capabilities to a system.
False
When used correctly, polymorphism will never require changes to be made to any part of the program.
False
Every object in C# knows its own class and can access this information through method
GetType()
The conventional name for an interface to be called Car is:
ICar
________ code is the process by which the compiler replaces method calls with the code of a method to improve performance.
Inling
The keyword sealed is applied to methods and classes to:
Prevent overriding and inheritance
Polymorphism enables you to?
Program in the general
Overloaded operator methods must be declared public and ________.
Static
2. The abstract methods and properties do not provide an implementation.
True
A class that implements an interface must define all methods and properties of that interface.
True
Abstract classes can provide data and services for objects.
True
An abstract base classes can be used to declare references.
True
An abstract class may be derived from another abstract class.
True
An interface is typically used in place of an abstract class when there is no default implementation to inherit.
True
An interface reference may invoke only the methods that the interface declares.
True
At least one argument of an operator overload method must be a reference to an object of the class in which the operator is overloaded.
True
Casting base class references to derived class references is known as downcasting.
True
Concrete classes provide implementations for every method and property they define.
True
If a derived class reference is assigned to a base class variable, the variable must be cast back to the derived class before any derived class methods can be called with it.
True
Methods that overload binary operators must take two arguments.
True
Operator is returns true if two matching types are being compared.
True
Operators should be overloaded to perform actions similar to those that they normally perform on objects of built-in types.
True
Polymorphism allows a programmer to command a wide variety of objects even if the programmer does not know the objects' types.
True
Polymorphism allows classes to be added with little or no modifications to the generic portion of a program.
True
Polymorphism enables objects of different classes that are related by a class hierarchy to be processed generically
True
The use of polymorphism helps promote software extensibility.
True
When a request is made to use a derived-class-object method through a base-class reference, C# polymorphically chooses the correct overridden method in the appro¬priate derived class that is associated with the object.
True
If a method needs to be called polymorphically, what type of reference should be used to point to the object that the method is being called with?
a reference of the base class that defines the behavior of the object
Polymorphism specifically enables the creation of programs that handle:
a wide variety of classes in a general manner
Which of the following statements about abstract base classes is true?
abstract base classes may contain data.
Interfaces can have ___ methods.
any number of
Assigning a derived class reference to a base class variable is safe:
because the derived class is an object of its base class.
Operator overloading is the process of:
enabling C#'s operators to work with class objects
Abstract classes may not be:
instantiated
A(n) ________ is best used for providing services that bring together disparate objects.
interface
If the base class contains only abstract method declarations, the base class is used for:
interface inheritance
The convention of the UML is to denote the name of an abstract class in:
italics
3. Keyword _______ is used to indicate a method overloads a specific operator.
operator
The purpose of an interface is to:
provide different types of objects with the same functionality, even though each will imple¬ment the functionality differently
4. Which declaration declares abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)?
public abstract int method1();
Constants declared in an interface are implicitly _______.
static
Polymorphisms involves
the same message sent to a variety of objects