Polymorphism and Abstract Classes: Multiple Choice Questions - Prof. Susanna Wei, Papers of Computer Science

Multiple choice questions related to polymorphism and abstract classes in object-oriented programming. Topics include encapsulation, inheritance, binding types, method overriding, and abstract methods. Students can use this document for self-study, exam preparation, or as a supplement to lecture notes.

Typology: Papers

Pre 2010

Uploaded on 08/16/2009

koofers-user-hny
koofers-user-hny 🇺🇸

5

(1)

10 documents

1 / 5

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chapter 8
Polymorphism and Abstract Classes
 Multiple ChoiceMultiple Choice
1) The principals of object oriented programming include:
(a) encapsulation
(b) inheritance
(c) polymorphism
(d) all of the above
2) ____________ refers to the process of associating a method definition with a method invocation.
(a) Binding
(b) Encapsulation
(c) Inheritance
(d) Polymorphism
3) __________ binding refers to the method definition being associated with the method invocation
when the code is compiled.
(a) Dynamic
(b) Late
(c) Early
(d) None of the above
4) __________ refers to the ability to associate many meanings to one method name by means of the
late binding mechanism.
(a) Inheritance
(b) Encapsulation
(c) Polymorphism
(d) None of the above
5) A method marked as final means the compiler uses ________ binding.
(a) dynamic
(b) early
1
pf3
pf4
pf5

Partial preview of the text

Download Polymorphism and Abstract Classes: Multiple Choice Questions - Prof. Susanna Wei and more Papers Computer Science in PDF only on Docsity!

Chapter 8

Polymorphism and Abstract Classes

 Multiple Choice

  1. The principals of object oriented programming include: (a) encapsulation (b) inheritance (c) polymorphism (d) all of the above
  2. ____________ refers to the process of associating a method definition with a method invocation. (a) Binding (b) Encapsulation (c) Inheritance (d) Polymorphism
  3. __________ binding refers to the method definition being associated with the method invocation when the code is compiled. (a) Dynamic (b) Late (c) Early (d) None of the above
  4. __________ refers to the ability to associate many meanings to one method name by means of the late binding mechanism. (a) Inheritance (b) Encapsulation (c) Polymorphism (d) None of the above
  5. A method marked as final means the compiler uses ________ binding. (a) dynamic (b) early 1

(c) late (d) none of the above

  1. Java does not use late binding for methods marked as: (a) final (b) static (c) private (d) all of the above
  2. Assigning an object of a derived class to a variable of a base class is called: (a) static binding (b) dynamic binding (c) upcasting (d) downcasting
  3. Assigning an object of an ancestor class to a descendent class is called: (a) static binding (b) dynamic binding (c) upcasting (d) downcasting
  4. The clone method has ________ parameters. (a) zero (b) one (c) two (d) three
  5. If you choose to use the method clone in your code, you must ___________ the clone method. (a) overload (b) encapsulate (c) override
  1. An abstract class must have the modifier ___________ included in the class heading. (a) static (b) abstract (c) final (d) private

 True/False

  1. Polymorphism refers to the ability to associate many meanings to one method through dynamic binding.
  2. Java allows an instance of an abstract class to be instantiated.
  3. Late binding refers to the method definition being associated with the method invocation when the method is invoked at run time.
  4. Early binding enables the compiler to be more efficient.
  5. The final modifier is included before the definition of the method, then the method can be redefined in a derived class.
  6. Java uses late binding with private methods, methods marked final, or static methods.
  7. The type of the variable naming an object determines which method names can be used in an invocation with that calling object.
  8. Downcasting should be used only in situations where it makes sense.
  9. The method clone has one parameter and should return a copy of the calling object.
  10. An abstract class is a class that has some methods without complete definitions.
  11. An abstract method serves as a placeholder for a method that must be defined in all derived classes.

 Short Answer/Essay

Explain the difference between early and late binding. What is polymorphism and how does it relate to late binding? What are the advantages of polymorphism? Write a decision statement to determine if an object should be downcast. Describe the limitations of the copy constructor. What is an abstract method? What is wrong with the following method definition? public abstract void doSomething(int count)

  1. Why should the instanceOf operator be used in conjunction with downcasting?
  2. Draw an inheritance hierarchy to represent a shoe object. The base class should have derived classes of Dress Shoes, Tennis Shoes and Boots.
  3. Implement the base class in the shoe hierarchy in number 9 above.
  4. Derive a class named Dress Shoes from the base class created in number 10 above.
  5. Derive a class named Tennis Shoes from the base class created in number 10 above.
  6. Derive a class named Boots from the base class created in number 10 above. private String heelType; //valid types include pumps, heels and flats

Override the clone method inherited in the Dress Shoes class created in number 11above. Override the clone method inherited in the Tennis Shoes class created in number 12 above. Override the clone method inherited in the Boots class created in number 13 above.