Wednesday, June 3, 2009

Polymorphism

1. For which of the following would polymorphism not provide a clean solution?
A) A program to compute a 5% savings account interest for a variety of clients.
B) An IRS program that maintains information on a variety of taxpayers and determines who to audit based on criteria for classes of taxpayers.
C) A billing program where there is a variety of clients who are billed with different fee structures.
D) A maintenance log program where a variety of machine data is collected and maintenance schedules are produced for each machine based on the data collected.

Points Earned: 1.0/1.0
Correct Answer(s): A




2. Assigning a derived class reference to a base class variable is safe ____
A) because the derived class has an object of its base class.
B) because the derived class is an object of its base class.
C) only when the base class is abstract.
D) only when the base class is concrete.

Points Earned: 1.0/1.0
Correct Answer(s): B




3. Polymorphism enables the programmer to:
A) hide information from the user.
B) absorb attributes and behavior from previous classes.
C) program in the specific.
D) program in the general.

Points Earned: 1.0/1.0
Correct Answer(s): D




4. Polymorphism involves:
A) the same message sent to a variety of objects
B) a specific message sent to each specific object
C) different messages sent to one object
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): A




5. Every object in C# knows its own class and can access this information through method ____.
A) ObjectClass()
B) GetInformation()
C) GetType()
D) ObjectInformation()

Points Earned: 1.0/1.0
Correct Answer(s): C




6. Abstract classes are classes which may not be:
A) inherited
B) accessed by derived-classes
C) instantiated
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): C




7. Which of the following is not true about interfaces?
A) An interface describes a set of methods that can be called on an object, providing a default implementation for the methods.
B) Interfaces are useful when attempting to assign common functionality to possibly unrelated classes.
C) An interface describes a set of methods that can be called on an object, without providing concrete implementation for the methods.
D) Once a class implements an interface, all objects of that class have an is-a relationship with the interface type.

Points Earned: 1.0/1.0
Correct Answer(s): A




8. Polymorphism specifically enables the creation of programs that handle:
A) classes that are containers for other classes
B) large amounts of data with efficiency
C) a wide variety of classes in a generic manner
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): C




9. Polymorphism allows for specifics to be dealt with during:
A) execution
B) programming
C) debugging
D) compilation

Points Earned: 1.0/1.0
Correct Answer(s): A




10. Which of the following statements about abstract base classes is true?
A) abstract base classes must declare all data members not given values as abstract.
B) abstract base classes must declare all methods as abstract.
C) abstract base classes may not contain implementations of methods.
D) abstract base classes may contain data.

Points Earned: 1.0/1.0
Correct Answer(s): D




11. 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 _________.
A) upcasting
B) increasecasting
C) decreasecasting
D) downcasting

Points Earned: 1.0/1.0
Correct Answer(s): D




12. Classes which may be instantiated are ___________ classes.
A) instance
B) concrete
C) abstract
D) None of the above

Points Earned: 1.0/1.0
Correct Answer(s): B




13. If the base class contains only abstract method declarations, the baseclass is used for:
A) implementation inheritance.
B) interface inheritance.
C) Both.
D) Neither.

Points Earned: 1.0/1.0
Correct Answer(s): B




14. Consider this abstract class:



public abstract class Foo
{
private int a;
public int b;

public Foo( int aVal, int bVal )
{
a = aVal;
b = bVal;
} // end Foo constructor

public abstract int calculate();
} // end class Foo

Any concrete subclass that extends class Foo ____



A) Must implement a method called calculate.
B) Will not be able to access the instance variable a.
C) Will not be able to instantiate an object of class Foo.
D) All of the above.

Points Earned: 1.0/1.0
Correct Answer(s): D




15. When a base class variable refers to a derived class object and a method is called on that object, the proper implementation is determined at execution time. What is the process of determining the correct method to call?
A) execution time binding.
B) late binding.
C) execution binding.
D) just in time binding.

Points Earned: 1.0/1.0
Correct Answer(s): B




16. The convention of the UML is to denote the name of an abstract class in:
A) a diamond
B) there is no convention of the UML to denote abstract classes-they are listed just as any other class
C) bold
D) italics

Points Earned: 1.0/1.0
Correct Answer(s): D




17. Which declaration declares abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)?
A) public int method1();
B) public int abstract method1();
C) public abstract int method1();
D) public int nonfinal method1();

Points Earned: 1.0/1.0
Correct Answer(s): C




18. Which statement best describes the relationship between base class and derived class types?
A) A derived class reference can be assigned to a base class variable and a base class reference can be assigned to a derived class variable.
B) 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.
C) A derived class reference cannot be assigned to a base class variable and a base class reference cannot be assigned to a derived class variable.
D) A base class reference can be assigned to a derived class variable, but a derived class reference cannot be assigned to a base class variable.

Points Earned: 1.0/1.0
Correct Answer(s): B




19. 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) a reference of the abstract class that defines the behavior of the object
B) a reference of the same type as the object
C) an object reference to the actual object
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): A




20. Keyword _______ is used to indicate a method overloads a specific operator.
A) operator
B) implement
C) overload
D) op

Points Earned: 1.0/1.0
Correct Answer(s): A




21. Declaring a method sealed means:
A) it cannot be overloaded
B) it will prepare the object for garbage collection
C) it cannot be accessed from outside its class
D) it cannot be overridden

Points Earned: 1.0/1.0
Correct Answer(s): D




22. The UML distinguishes an interface from other classes by placing the word "interface" in above the interface name.
A) bold.
B) guillemets.
C) carets.
D) italics.

Points Earned: 1.0/1.0
Correct Answer(s): B




23. Which of the following does not complete the sentence correctly? An interface ____.
A) is used in place of an abstract class when there is no default implementation to inherit.
B) forces classes that implement it to declare all the interface methods.
C) cannot be instantiated.
D) can be instantiated.

Points Earned: 1.0/1.0
Correct Answer(s): D




24. Operator overloading is the process of:
A) enabling C#'s operators to work with class objects
B) using operators to create new classes
C) using operators to specify which versions of overloaded methods to use
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): A




25. A class that implements an interface but does not declare all of the interface's methods must be declared:
A) abstract
B) interface
C) public
D) final

Points Earned: 1.0/1.0
Correct Answer(s): A




26. The conventional name for an interface to be called Car is: ____
A) InterfaceCar
B) ICar
C) CarI
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): B




27. ________ code is the process by which the compiler replaces method calls with the code of a method to improve performance.
A) Debugging
B) Inlining
C) Compiling
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): B




28. The keyword sealed is applied to methods and classes to:
A) prevent overriding and inheritance
B) guarantee an implementation exists
C) specify a class is concrete
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): A




29. Interfaces can have ____ methods.
A) any number of
B) 0
C) 2
D) 1

Points Earned: 1.0/1.0
Correct Answer(s): A




30. A(n) ________ is best used for providing services that bring together disparate objects.
A) abstract class
B) concrete class
C) interface
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): C




31. The purpose of an interface is to: ____
A) provide similar objects with the same functionality, even though each will implement the functionality differently
B) provide different objects with the same functionality, even though each will implement the functionality differently
C) provide default implementations of methods and properties
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): B




32. All of the following methods are implicitly sealed except:
A) a private method.
B) a method in an abstract class.
C) a method declared in a sealed class.
D) static method.

Points Earned: 1.0/1.0
Correct Answer(s): B




33. Which of the following characteristics can be used to create an interface for a file, a cat and a house?
A) door
B) tail
C) age
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): C




34. Constants declared in an interface are implicitly _______.
A) private.
B) static.
C) abstract.
D) All of the above.

Points Earned: 1.0/1.0
Correct Answer(s): B




35. Overloaded operator methods must be declared public and ________.
A) sealed
B) protected
C) static
D) None of the above.

Points Earned: 1.0/1.0
Correct Answer(s): C




36. Classes and methods are declared sealed for all of the following reasons, except:
A) sealed methods are static.
B) sealed methods and classes prevent further inheritance.
C) sealed methods allow inlining the code.
D) sealed methods can improve performance.

Points Earned: 1.0/1.0
Correct Answer(s): A




37. Which is used to specify that a class will be implementing an interface?
A) extends.
B) using
C) :
D) implements

Points Earned: 1.0/1.0
Correct Answer(s): C




38. Polymorphism allows classes to be added with little or no modifications to the generic portion of a program.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




39. The abstract methods and properties do not provide an implementation.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




40. The programmer may define implementations for abstract methods to act as a default.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




41. The use of polymorphism helps promote software extensibility.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




42. An abstract base classes can be used to declare references.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




43. An abstract class may be derived from another abstract class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




44. 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 appropriate derived class that is associated with the object.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




45. 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.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




46. The major drawback to polymorphically designed programs is that they do not take into account the future addition or deletion of classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




47. It is common object-oriented programming to define an iterator class that can walk through all the objects in a container (such as an array).A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




48. When used correctly, polymorphism will never require changes to be made to any part of the program.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




49. The abstract keyword has the same effect as the virtual keyword.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




50. Casting base class references to derived class references is known as downcasting.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




51. Concrete classes provide implementations for every method and property they define.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




52. Polymorphism is particularly effective for implementing layered software systems.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




53. Polymorphism allows a programmer to command a wide variety of objects even if the programmer does not know the objects' types.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




54. Polymorphism enables objects of different classes that are related by a class hierarchy to be processed generically.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




55. Objects of abstract base classes can be instantiateD.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




56. All methods in an abstract class are inherently abstract.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




57. Polymorphism allows the addition of classes providing they were at least considered during program development.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




58. Unfortunately, polymorphic programs make it difficult to add new capabilities to a system.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




59. A class that implements an interface must define all methods and properties of that interface.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




60. An interface is typically used in place of an abstract class when there is no default implementation to inherit.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




61. An interface is used when there is a default implementation to inherit.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




62. Operators should be overloaded to perform similar actions they normally perform on objects of built-in types.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




63. All static and private methods are implicitly sealed.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




64. Abstract classes are used to provide data and services for objects.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




65. Sealing methods allows the compiler to optimize the program by "inlining code."A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




66. All .NET languages support operator overloading.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




67. Excessive use of operator overloading can make a program difficult to read.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




68. An interface may not provide properties with get and set accessors.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




69. All methods in a sealed class must be explicitly declared sealed.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




70. An abstract class cannot have instance data and non-abstract methods.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




71. Methods that overload binary operators must take two arguments.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




72. Attempting to instantiate an object of an abstract class is a logic error.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




73. 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.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




74. An interface reference may only invoke the methods that the interface declares.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




75. is returns true if two matching types are being compared.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




76. If a class leaves one method in an interface undeclared, the class is implicitly declared by C# as an abstract class.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




77. Interface methods may receive arguments.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): True




78. Declaring an interface protected allows for extra security precautions.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False




79. An class that implements an interface may not act as a base class for other classes.A) True
B) False

Points Earned: 1.0/1.0
Correct Answer(s): False

1 comment: