1620 Java Test 2 - Website Chp 09 Inheritance 2

of 3
9 views
PDF
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
Document Description
Java How to Program, 5/e Test Item File 1 of 3 Chapter 9 Section 9.1 9.1 Q1: Which of the following statements is not true? a.A subclass is generally larger than its superclass. b.A superclass object is a subclass object. c.The class following the extends keyword in a class declaration is the direct superclass of the class being declared. d.Java uses interfaces to provide the benefits of multiple inheritance. ANS: b. A superclass object is a subclass object. 9.1 Q2: Which term applies to the l
Document Share
Document Tags
Document Transcript
  Java How to Program, 5/e Test Item File1 of 3 © Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved. Chapter 9Section 9.19.1 Q1: Which of the following statements is not true?a.A subclass is generally larger than its superclass.b.A superclass object is a subclass object.c.The class following the extends keyword in a class declaration is the direct superclass of the class beingdeclared.d.Java uses interfaces to provide the benefits of multiple inheritance.ANS: b. A superclass object is a subclass object.9.1 Q2: Which term applies to the largest class in a class hierarchy?a.Superclass.b.Subclass.c.Base class.d.Parent class.ANS: a. Superclass.9.1 Q3: Focusing on the commonalities among objects in a system rather than specifics is known asa.Encapsulation.b.Abstraction.c.Inheritance.d.Simplification.ANS: b. Abstraction.9.1 Q4: Inheritance is also known as thea.“knows-a” relationship.b.“has-a” relationship.c.“uses-a” relationship.d.“is-a” relationship.ANS: b. “has-a” relationshipSection 9.29.2 Q1: Which of the following is not a superclass/subclass relationship?a.Ford/Taurus.b.University/Brown University.c.Sailboat/Tugboat.d.Country/USA.ANS: c. Sailboat/Tugboat. A Sailboat is not a superclass for Tugboats. Both sailboat and tugboats would besubclasses of Boat.9.2 Q2: An advantage of inheritance is that:a.All methods can be inherited.b.All instance variables can be uniformly accessed by subclasses and superclasses.c.Objects of a subclass can be treated like objects of their superclass.d.None of the above.ANS: c. Objects of a subclass can be treated like objects of their superclass. Note: constructors cannot be inherited,and instance variables that are private in a superclass cannot be directly accessed by a subclass.Section 9.39.3 Q1: Which of the following keywords allows a subclass to access a superclass method even when the subclasshas overridden the superclass method?a. protected .b. this .c. public .d. super .ANS: d. super .9.3 Q2: Using the protected keyword gives a member:  Java How to Program, 5/e Test Item File2 of 3 © Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved. a. public access.b. package access.c. private access.d. block scope.ANS: b. package access.9.3 Q3: Superclass methods with this level of access cannot be called from subclasses.a. private .b. public .c. protected .d. package .ANS: a. private .Section 9.49.4 Q1: Overriding a method differs from overloading a method because:a.For an overloaded constructor, the superclass constructor will always be called first.b.For an overridden constructor, the superclass constructor will always be called first.c.Overloaded methods have the same signature.d.Overridden methods have the same signature.ANS: d. Overridden methods have the same signature.9.4 Q2: Consider the classes below, declared in the same file: class A {int a;public A() {a = 7;}}class B extends A {int b;public B() {b = 8;}} Which of the statements below is not true?a.Both variables a and b   are instance variables.b.After the constructor for class   B is executed, the variable a will have the value 7 .c.After the constructor for class   B is executed, the variable b will have the value 8 .d.A reference to class   A can be treated as a reference to class   B .ANS: d. A reference to class   A can be treated as a reference to class   B . The converse is true because classA is the superclass. Note that variables a and b both have package access.9.4 Q3: Accessing a superclass method through a subclass reference isa.Polymorphism.b.Inheritance.c.A syntax error.d.Straightforward.ANS: c. A syntax error.9.4 Q4: private fields of a superclass can be accessed in a subclassa.by calling private methods declared in the superclass.b.by calling public or protected methods declared in the superclass.c.directly.d.All of the above.  Java How to Program, 5/e Test Item File3 of 3 © Copyright 2003 by Deitel & Associates, Inc. and Prentice Hall. All Rights Reserved. ANS: b. calling public or protected methods declared in the superclass.Section 9.5( none )Section 9.69.6 Q1: Which statement below is not true?a.Superclass finalizers should always be called as the last statement of a subclass finalizer.b.Superclass constructors should always be called as the first statement of a subclass constructor.c.Finalizers and constructors should always be declared protected so subclasses have access to the method.d.All are not true.ANS: c. Finalizers and constructors should always be declared protected so subclasses have access to themethod. Constructors should be declared public so classes that use their classes can instantiate them.9.6 Q2: Finalizers are used to:a.Clean up an object of a class before it is garbage collected.b.Draw the applet or JFrame used by an application.c.Initialize variables.d.Ensure than all variables are assigned valid values.ANS: a. Clean up an object of a class before it is garbage collected.9.6 Q3: Which of the following sequences is in the correct order?a.Subclass constructor, superclass constructor, subclass finalizer, superclass finalizer.b.Superclass constructor, subclass constructor, superclass finalizer, subclass finalizer.c.Subclass constructor, superclass constructor, superclass finalizer, subclass finalizer.d.Superclass constructor, subclass constructor, subclass finalizer, superclass finalizer.ANS: d. Superclass constructor, subclass constructor, subclass finalizer, superclass finalizer.Section 9.79.7 Q1: Which of the following statements are true?A.We can use inheritance to customize existing software.B.A superclass specifies commonality.C.A superclass can be modified without modifying subclassesD.A subclass can be modified without modifying its superclass.a.All of the above.b.None of the above.c.A, B and C.d.A, B and D.ANS: a. All of the above.9.7 Q2: Which of the following is an example of a functionality that should not be “factored out” to a superclass?a.Both ducks and geese are birds that know how to start flying from the water.b.All vehicles know how to start and stop.c.All animals lay eggs, except for mammals.d.All paints have a color.ANS: c. All animals lay eggs except for mammals.
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks
SAVE OUR EARTH

We need your sign to support Project to invent "SMART AND CONTROLLABLE REFLECTIVE BALLOONS" to cover the Sun and Save Our Earth.

More details...

Sign Now!

We are very appreciated for your Prompt Action!

x