Chapter 10: Object-Oriented Programming: Polymorphism

Ace your homework & exams now with Quizwiz!

Which of the following is not possible?

A class that inherits from two classes.

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. Because there is only one kind of calculation, there is no need for polymorphism.

Which statement best describes the relationship between superclass and subclass types?

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

Which of the following statements is false?

An advantage of inheritance over interfaces is that only inheritance provides the is-a relationship. Actually, when a class implements an interface, the same is-a relationship provided by inheritance applies.

Which of the following statements is false?

Anonymous methods provide a shorthand notation for creating lambdas. Actually, lambdas provide a shorthand notation for creating anonymous methods.

Which interface is used to identify classes whose objects can be written to or read from some type of storage or transmitted across a network?

AutoCloseable.

Which of the following is false?

It's OK to any of a class's methods from its constructors.

Which of the following statements is false?

References to interface types do not have access to method toString. Actually, all references, including those of interface types, refer to objects that extend Object and therefore have a toString method.

Which of the following statements is false?

When you enhance an existing interface with default methods—any class that implemented the original interface will break. Actually, when you enhance an existing interface with default methods—any class that implemented the original interface will not break—it'll simply receive the

Which of the following statements is false?

With non-static interface methods, helper methods can now be declared directly in interfaces rather than in separate classes. Actually, it's with static interface methods that helper methods can now be declared directly in interfaces rather than in separate classes.

All of the following methods are implicitly final except:

a method in an abstract class.

A class that implements an interface but does not declare all of the interface's methods must be declared ________.

abstract

A(n) class cannot be instantiated.

abstract

Which of the following statements about abstract superclasses is true?

abstract superclasses may contain data.

Interfaces can have methods.

any number of

Assigning a subclass reference to a superclass variable is safe ________.

because the subclass object is an object of its superclass.

Which of the following does not complete the sentence correctly?

can be instantiated.

Non-abstract classes are called ________.

concrete classes.

Polymorphism allows for specifics to be dealt with during:

execution

Classes and methods are declared final for all but the following reasons:

final methods are static.

Every object in Java knows its own class and can access this information through method .

getClass

The UML distinguishes an interface from other classes by placing the word "interface" in above the interface name.

guillemets.

Which keyword is used to specify that a class will define the methods of an interface?

implements

If the superclass contains only abstract method declarations, the superclass is used for ________.

interface inheritance.

Declaring a method final means:

it cannot be overridden.

It is a UML convention to denote the name of an abstract class in ________.

italics

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?

late binding (also called dynamic binding).

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();}

must implement a method called calculate will not be able to access the instance variable a. 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?

none of the above

Polymorphism enables you to:

program in the general.

Which of the following could be used to declare abstract method method1 in abstract class Class1 (method1 returns an int and takes no arguments)?

public abstract int method1();

In Java SE 7 and earlier, an interface may contain:

public static final data and public abstract methods.

Which interface is used to identify classes whose objects can be written to or read from some type of storage or transmitted across a network?

serializeable


Related study sets

Bio- Life Science Khan Based (Part 10) Membrane transport, Passive, Active, Bulk-Facilitated, Na-K Pump, Uniporters, Symporters, Antiporters

View Set

Chapter 2 practice test questions

View Set

Module 3 lessons learned points earned

View Set

Las estaciones y los meses del año: Spanish 1

View Set

Global Supply Chain Midterm Fall I 2020

View Set

Chapter 8 Motivation and reward system management

View Set