Ch. 10

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

False. The correct answer is: you *cannot* treat a superclass object as a subclass object, because a superclass object is not an object of any of its subclasses.

True or False: you *can* treat a superclass object as a subclass object, because a superclass object is not an object of any of its subclasses.

*Does specify* what operations are allowed. *Does not specify* how they're performed.

What *does* an interface specify about operations? What *does it not* specify about operations?

Implementing an interface

What allows objects of these classes to be processed polymorphically—objects of classes that *implement* the same interface can respond to all of the *interface* method calls.

A superclass reference

What can be used to invoke only the methods declared in the superclass?

to provide an appropriate superclass from which other classes can inherit and thus share a common design.

What is the purpose of an Abstract Class?

It must provide concrete implementations

What must each subclass of an abstract superclass provide of each of the superclass's abstract methods?

is-a

When a class implements an interface, the same ( is-a / has-a ) relationship provided by inheritance applies.

require direct knowledge of the new classes that we add to the hierarchy.

When a program is *extensible* the only parts of a program that must be altered are those that

subclass

When a superclass variable contains a reference to a subclass object, and that reference is used to call a method, the *( subclass / superclass )* version of the method is called

When unrelated (disparate) classes need to share common methods and constants

When is an interface typically used?

the specifics

When processing objects polymorphically, we typically do not need to worry about

checking the variable's class type.

When the compiler encounters a method call made through a variable, the compiler determines if the method can be called by...

object of the interface *type*

Objects of any subclasses of the class that implements the interface can also be thought of as...

A superclass reference

Only a reference to *what* can be used to invoke only the methods of the superclass—the subclass method implementations are invoked polymorphically.

new objects

Only client code that instantiates "____" "____" must be modified to accommodate new types

extensibility

Polymorphism promotes "____": Software that invokes polymorphic behavior is independent of the object types to which messages are sent.

False. The correct answer is: *NOT ALL* hierarchies contain abstract classes

True or False: All hierarchies contain abstract classes.

False! An abstract method *can* include methods with implementations *and* abstract methods

True or False: All methods in an *abstract class* must be declared as abstract methods.

True.

True or False: An object of a class that implements an interface may be thought of as an object of that interface type.

False! Only a *concrete subclass* must implement the method.

True or False: If a superclass declares and *abstract method*, a *subclass* must implement that method.

False! Trying to invoke a subclass-only method with a *superclass* variable is *NOT* allowed.

True or False: Invoking a *subclass only* method through a *subclass* variable is not allowed.

FALSE! You *should not* call overridable methods from constructors

True or False: You should call overridable methods from constructors

True

True or False: super- class variables are intended to refer to superclass objects, and subclass variables are intended to refer to subclass objects

Java interface

A "____" "____" describes a set of meth- ods that can be called on an object to tell it, for example, to perform some task or return some piece of information.

Polymorphism

"____" involves using a superclass variable to invoke methods on superclass and subclass objects, enabling you to "program in the general."

in the specific

*Occasionally*, when performing polymorphic processing, we need to program "_______________________"

realize

A class is said to "____", or *implement*, the methods of an interface.

abstract class

A class that contains *any* abstract methods must be declared as an...

explicitly

A class that contains any abstract methods must be ( implicitly / explicitly ) declared abstract even if that class contains some concrete (nonabstract) methods.

- abstract - abstract

A class that does not implement all the methods of the interface is an "____" class and must be declared "____".

Incomplete

Abstract Classes classes cannot be used to instantiate objects, because they're "____"

Downcasting

Enables the program to invoke subclass methods that are not in the superclass

what is common among subclasses

Abstract superclasses are too general to create real objects. They specify only...

1. public 2. static 3. final

All *fields* declared in an interface are implicitly... (There are three answers)

public abstract

All *methods* declared in an interface are implicitly what kind of methods?

Dynamic Binding or Late Binding

All calls to method toString are resolved at execution time, based on the type of the object to which a method refers. This process is known as...

public

All interface members must be ( public / protected / private ). Choose one.

One or more

An abstract class *normally* contains how many abstract methods?

Polymorphism

Enables us to write programs that process object that share the same superclasses as if they were all object of the superclass; this can simplify programming.

Polymorphism

Enables you to "program in the general" rather than "program in the specific."

1. Constants 2. abstract methods

An interface declaration begins with the keyword interface and contains only what two things?

dynamic binding

As a result of "____" "____", Java decides which class's toString method to call at execution time rather than at compile time.

compilation error

Assigning a superclass variable to a subclass variable is a....

Dynamic Binding

At execution time, the type of the object to which the variable refers determines the actual method to use. This process is called....

compilation

Attempting to declare a subclass of a final class is a "____" error

Abstract Superclasses

Because Abstract Classes are used only as superclasses in inheritance hierarchies, we refer to them as...

Polymorphism

Enables you to write programs that process objects that share the same superclass, either directly or in- directly, as if they were all objects of the superclass;

NO!!!

Can a final *class* be extended to create a subclass?

No. this guarantees that the final method implementation will be used by all direct and indirect subclasses in the hierarchy.

Can a final method be overridden in a subclass? Why or why not?

No they cannot!

Can constructors and static methods be declared abstract?

downcasting

Casting a reference stored in a superclass *variable* to a superclass *type* is called "____"

concrete

Class from which object can be instantiated are called "____" classes.

Concrete Classes

Classes that can be used to instantiate objects are called

Concrete Classes

Classes that can be used to instantiate objects are called...

instantiate objects

Concrete classes provide the specifics that make it reasonable to...

No!

Do abstract method provide implementations?

No you do not! Because they are always public and abstract

Do you need to declare interface *methods* as public and abstract? Why or why not?

device driver

For each device, the operating system uses a piece of software called a "____" "____" to control all communication between the system and the device.

abstract

If a class contains at least one abstract method, it's a(n) "____" class.

1. superclass 2. subclass

If a program needs to perform a subclass-specific operation on a subclass object referenced by a superclass variable, the program must first cast the *(subclass / superclass )* reference to a *( subclass / superclass )* reference through a technique known as downcasting.

references

Like public abstract *classes*, interfaces are typically public ( types / references ).

abstract

Methods that *are not* interface methods and *do not* provide implementations are declared using the keyword "____."

final

Methods that are declared static are also implicitly...

Interfaces

Software object communicate via...

Abstract Classes

Sometimes it's useful to declare classes for which you never intend to create objects. These classes are called...

Something is "extensible"

Technique in which new classes can be added with little or no modification to the general portions of the program, as long as the new classes are part of the inheritance hierarchy that the program processes generically.

up

The *is-a* relationship applies only ( up / down ) the hierarchy from a subclass to its direct (and indirect) superclasses, and not vice versa!

explicitly

The Java compiler allows the assignment of a superclass reference to a subclass variable if we (implicitly / explicitly ) cast the *superclass reference* to the *subclass type*

realization

The UML expresses the relationship between a class and an interface through a relationship known as...

Abstract Class

The primary purpose of this *class* is to provide an appropriate superclass from which other classes can inherit and this share a common design.

Abstract Classes

These *classes* cannot be used to instantiate objects, because they're incomplete.

Abstract Classes

These *classes* sometimes constitute several levels of a hierarchy.

public default methods

These *methods* with *concrete default* implementations specify how operations are performed when an implementing class does not override the methods.

Concrete Classes

These classes provide implementations of every method they declare.

an interface

This is often used in place of an abstract class when there's no default implementation to inherit—that is, no fields and no default method implementations.

a concrete class

To use an interface, *what* *must* specify that it implements the interface and *must* declare each method in the interface with the signature specified in the interface declaration?

False! Abstract methods *DO NOT* provide implementations.

True or False: Abstract methods provide implementations.

because it's not possible to override them in a subclass

Why are methods that are declared private implicitly final?

To reduce client code's dependencies on specific subclass types

Why do programmers often write client code that uses only abstract superclasses?

extensible

With polymorphism, we can design and implement systems that are easily "____"

default methods

With these methods, you can instead declare common method implementations in interfaces, which gives you more flexibility in designing your classes.

abstract

You can make an *abstract* class by declaring it with the *keyword*...

Abstract Method

an instance method with keyword abstract in its declaration

compilation errors.

attempting to invoke subclass-only methods through a superclass reference results in...

Interfaces

define and standardize the ways in which things such as people and systems can interact with one another

Polymorphism

enables you to deal in generalities and let the execution-time environment handle the specifics.

the type of the referenced object, not the type of the variable

invoking a method on a subclass object via a superclass reference invokes the subclass functionality. What determines which method is called?

Polymorphism

occurs when a program invokes a method through a superclass variable—at execution time, the correct subclass version of the method is called, based on the type of the reference stored in the superclass variable.

Polymorphism

particularly effective for implementing so-called layered software systems

interfaces

particularly useful for assigning common functionality to possibly unrelated classes.


संबंधित स्टडी सेट्स

Chapter 9 muscle fibers and tissue

View Set

Endocrinology, Anterior Pituitary and Hypothalamus

View Set

past quizzes and turning point ?s

View Set

Chapter 22, Nurse Leader, Manager, and Care Coordinator

View Set

Analyzing and Evaluating Research & Systematic Reviews

View Set