Chapter 9 and 10

Ace your homework & exams now with Quizwiz!

private fields of a superclass can be accessed in a subclass Select one: A. 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.

B. by calling public or protected methods declared in the superclass.

Which of the following statements is false? Select one: A. An advantage of inheritance over interfaces is that only inheritance provides the is-a relationship. B. Objects of any subclass of a class that implements an interface can also be thought of as objects of that interface type. C. When a method parameter is declared with a subclass or interface type, the method processes the object passed as an argument polymorphically. D. All objects have the methods of class Object.

A. An advantage of inheritance over interfaces is that only inheritance provides the is-a relationship. Yep this is false. Both inheritance and interfaces define an is-a relationship.

Which of the following statements is false? Select one: A. References to interface types do not have access to method toString. B. Method toString can be invoked implicitly on any object. C. With inheritance, classes and their inherited classes tend to be very similar. D. Dramatically different classes can often meaningfully implement the same interface.

A. References to interface types do not have access to method toString.

Which superclass members are inherited by all subclasses of that superclass? Select one: A. all instance variables and methods. B. only public instance variables and methods. C. only public and protected instance variables and methods. D. all except static variables and methods

A. all instance variables and methods. Yep, everything is inherited. Keep in mind that subclasses cannot see the private members inherited from the superclass.

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

A. execution. Yep at execution time which specific implementation is executed depends on the object being referenced.

Every object in Java knows its own class and can access this information through method . Select one: A. getClass. B. getInformation. C. objectClass. D. objectInformation.

A. getClass.

Superclass methods with this level of access cannot be called from subclasses. Select one: A. private B. public C. protected D. package

A. private Yep, private is private to all classes. A subclass may have the private member of the superclass, just cannot see or access those members.

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

A. program in the general.

The default equals implementation of class Object determines: Select one: A. whether two references refer to the same object in memory. B. whether two references have the same type. C. whether two objects have the same instance variables. D. whether two objects have the same instance variable values.

A. whether two references refer to the same object in memory.

Which of the following is not possible? Select one: A. A class that implements two interfaces. B. A class that inherit (extend) from two classes. C. A class that inherit (extend) from one class, and implements an interface. D. All of the above are possible.

B. A class that inherit (extend) from two classes. Yes this is false. Java only supports single inheritance. A class cannot inherit implementations for multiple sources.

Every class in Java, except ________, extends an existing class. Select one: A. Integer B. Object C. String D. Class

B. Object Yep, Object is the root of the inheritance hierarchy. It does not extend anything else.

Overriding a method differs from overloading a method because: Select one: A. Overloaded methods have the same signature. B. Overridden methods have the same signature. C. Both of the above. D. Neither of the above.

B. Overridden methods have the same signature. Yep, overridden methods must have the same signature, otherwise they would be overloaded. Must take care when overriding a method to have the same signature. The @overriden attribute can catch these errors at compile time.

Assigning a subclass reference to a superclass variable is safe ________. Select one: A. because the subclass object has an object of its superclass. B. because the subclass object is an object of its superclass. C. only when the superclass is abstract. D. only when the superclass is concrete.

B. because the subclass object is an object of its superclass.

Which keyword is used to specify that a class will define the methods of an interface? Select one: A. uses B. implements C. defines D. extends

B. implements Yes it is implements.

Which of the following is the superclass constructor call syntax? Select one: A. keyword super, followed by a dot (.) . B. keyword super, followed by a set of parentheses containing the superclass constructor arguments. C. keyword super, followed by a dot and the superclass constructor name. D. None of the above.

B. keyword super, followed by a set of parentheses containing the superclass constructor arguments. Yep, this is the correct way of calling the superclass constructor.

Which of the following statements is false? Select one: A. Java allows a class to implement multiple interfaces in addition to extending one class. B. Classes declared with implementation inheritance are tightly coupled. C. Classes declared with interface inheritance are tightly coupled. D. An interface also may extend one or more other interfaces.

C. Classes declared with interface inheritance are tightly coupled. This is false, disparate classes can implement the same interface. Such classes are far from being tightly coupled.

Which of the following statements is false? Select one: A. A class can directly inherit from class Object. B. It's often much more efficient to create a class by inheriting from a similar class than to create the class by writing every line of code the new class requires. C. If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. D. A class's instance variables are normally declared private to enforce good software engineering.

C. If the class you're inheriting from declares instance variables as private, the inherited class can access those instance variables directly. Yep this is false. Private is private and only a class can see and access its private members. A subclass will have the private members of the superclass, just cannot see or access them.

Which of the following is not a superclass/subclass relationship? Select one: A. Employee/Hourly Employee. B. Vehicle/Car. C. Sailboat/Tugboat. D. None of the above.

C. Sailboat/Tugboat. Hmmm, a Tugboat a special kind of Sailboat? I don't think so. Yep the is the wrong example. Sailboat and Tugboat maybe special kinds of boats but neither one is a special kind of the other.

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

C. abstract.

A(n) _________ class cannot be instantiated. Select one: A. final B. concrete. C. abstract D. polymorphic.

C. abstract. Yep, an abstract class indicates it maybe missing some implementations. Therefore cannot create instances with missing implementations.

When overriding a superclass method and calling the superclass version from the subclass method, failure to prefix the superclass method name with the keyword super and a dot (.) in the superclass method call causes ________. Select one: A. a compile-time error. B. a syntax error. C. infinite recursion. D. a runtime error.

C. infinite recursion.

Which statement best describes the relationship between superclass and subclass types? Select one: A. A an instance of a subclass cannot be assigned to a superclass variable and an instance of a superclass cannot be assigned to a subclass variable. B. A subclass instance can be assigned to a superclass variable and a superclass instance can be assigned to a subclass variable. C. A superclass instance can be assigned to a subclass variable, but a subclass reference cannot be assigned to a superclass variable. D. A subclass instance can be assigned to a superclass variable, but a superclass instance cannot be assigned to a subclass variable.

D. A subclass instance can be assigned to a superclass variable, but a superclass instance cannot be assigned to a subclass variable.

Which statement is true when a superclass has protected instance variables? Select one: A. A subclass object can assign an invalid value to the superclass's instance variables, thus leaving an object in an inconsistent state. B. Subclass methods are more likely to be written so that they depend on the superclass's data implementation. C. We may need to modify all the subclasses of the superclass if the superclass implementation changes. D. All of the above.

D. All of the above.

Consider the abstract superclass below: public abstract class Foo {private int a;public int b; public Foo(int aVal, int bVal) {a = aVal;b = bVal;} public abstract int calculate();} Any concrete subclass that extends class Foo: Select one: A. Must implement a method called calculate. B. Will not be able to access the instance variable a. C. Neither (a) nor (b). D. Both (a) and (b).

D. Both (a) and (b).

Consider classes A, B and C, where A is an abstract superclass, B is a concrete class that inherits from A and C is a concrete class that inherits from B. Class A declares abstract method originalMethod, implemented in class B. Which of the following statements is true of class C? Select one: A. Method originalMethod cannot be overridden in class C - once it has been implemented in concrete class B, it is implicitly final. B. Method originalMethod must be overridden in class C, or a compilation error will occur. C. If method originalMethod is not overridden in class C but is called by an object of class C, an error occurs. D. None of the above.

D. None of the above.

When a subclass constructor calls its superclass constructor, what happens if the superclass's constructor does not assign a value to an instance variable? Select one: A. A syntax error occurs. B. A compile-time error occurs. C. A run-time error occurs. D. The program compiles and runs because the instance variables are initialized to their default values.

D. The program compiles and runs because the instance variables are initialized to their default values.

Interfaces can have _______ methods. Select one: A. 0 B. 1 C. 2 D. any number of

D. any number of

Which of the following does not complete the sentence correctly?An interface . Select one: A. forces concrete classes that implement it to declare to provide implementations of all the methods declared in the interface. B. can be used in place of an abstract class when there is no default implementation to inherit. C. is declared in a file by itself and is saved in a file with the same name as the interface followed by the .java extension. D. can be instantiated.

D. can be instantiated.

Inheritance is also known as the Select one: A. knows-a relationship. B. has-a relationship. C. uses-a relationship. D. is-a relationship.

D. is-a relationship.

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

D. it cannot be overridden.

When a superclass variable refers to a subclass 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? Select one: A. early binding. B. non-binding. C. on-time binding. D. late binding.

D. late binding.

Which of the following keywords allows a subclass to access a superclass method even when the subclass has overridden the superclass method? Select one: A. base. B. this. C. public. D. super.

D. super.


Related study sets

Chapter 3 - Social Cognitive Theories/Self-Efficacy

View Set

HA3325: History Language Culture Terms 51-100

View Set

chapter 9 - interest groups and political parties

View Set

Salesfoce Adminstrator Certification

View Set

(Research) TExES English Language Arts and Reading 7-12 (231)

View Set

Interior & Exterior Angles of Polygons PRACTICE

View Set

Procedures I Ch 2 positioning & problem solving

View Set

Bmal 590 Operations/Production Management_Master Set

View Set