Ch. 09

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

is-a relationship

This relationship represents inheritance. In this relationship, an object of a subclass can also be treated as an object of its superclass—e.g., a car is a vehicle

True, a subclass can access non-private members of its superclass

True or False: A subclass cannot access the private members of its superclass, but it can access the non-private members.

Protected

Inheriting ( public / protected / private ) instance variables enables direct access to the variables by subclasses. Choose one from the paren list.

Private

Inheriting protected instance variables enables direct access to the variables by subclasses. In most cases, however, it's better to use ( public / protected / private ) instance variables to encourage proper software engineering. Choose one from the paren list.

True

True or False: A subclass can become a superclass for future subclasses.

True

True or False: A superclass's protected members are accessible by all subclasses of that superclass.

True

True or False: All public and protected superclass members retain their original access modifier when they become members of the subclass.

False. The correct answer is: Not every class relationship is an inheritance relationship.

True or False: Every class relationship is an inheritance relationship.

False, the correct answer is: Declaring a subclass does not affect its superclass's source code. Inheritance preserves the integrity of the superclass.

True or False: Declaring a subclass affects its superclass's source code. Inheritance does not preserve the integrity of the superclass

class hierarchy

defines the inheritance relationships among classes

Inheritance

"____" is a form of software reusability in which new classes acquire the members of existing classes and embellish those classes with new capabilities

1. Single Inheritance 2. This means that each class is derived from exactly one direct superclass.

1. Which type of inheritance does Java support. 2. What does this mean?

1. subclass 2. superclass

A 1.( subclass / superclass ) can customize methods that it inherits from its 2.( subclass / superclass ).

inheritance hierarchy

A sample class hierarchy is also sometimes called an...

more

A subclass can add its own fields and methods. Therefore, a subclass is ( more / less ) specific than its superclass and represents a more specialized group of objects.

overrides

A subclass can customize methods that it inherits from its superclass. To do this, the subclass "____" or (redefines) the superclass method with an appropriate implementation

public and protected

A superclass's "____" and "____" members can be accessed in the superclass declaration AND in subclass declaration

public

A superclass's "____" members are accessible anywhere that the program has a reference to an object of that superclass or to an object of one of its subclasses.

protected

A superclass's "____" members can be accessed by members of that superclass, by members of its subclasses and by members of other classes in the *same package*

private

A superclass's ( public / protected / private ) members can be accessed directly only within the superclasses declaration. Choose one from the paren list.

has a reference to an object of that superclass or one of its subclasses

A superclass's public members are accessible wherever the program....

Deep Copy

A typical overridden clone method's implementation would perform a "____" "____" that creates a *new object* for *each* reference-type instance variable.

overridden

An "____" superclass method can be accessed from a subclass if the superclass method name is preceded by "super" and a dot ( . ) separator

indirect superclass

An "_____" "_____" is any class above the direct superclass in the class hierarchy

No, they are not!

Are constructors inherited?

getClass

Every object in Java knows its own type at execution time. Which method returns an object of class Class (package java.lang) that contains information about the object's type, such as its class name

No, a superclass is not an object of its subclasses

Every object of a subclass is also an object of that class's superclass. Is a superclass then an object of its subclasses?

By using the superclass constructor call syntax -- keyword super, followed by a set of parentheses containing the superclass constructor arguments EX: super(firstName, lastName, socialSecurityNumber, grossSales, commissionRate);

How does a subclass call one of its superclass's constructors?

By expressing their common capabilities in the superclass's members.

How is it possible to treat superclass objects and subclass objects similarly?

Yes, they can be!

If constructors are not inherited, can they still be available to be called by subclasses?

Object

In Java, the class hierarchy begins with class "____", which every class in Java directly or indirectly extends (or inherits)

'has-a' or composition

In a(n) "____" relationship, a class object of has references to objects of other classes as members

'is-a' or inheritance

In a(n) "____" relationship, an object of a subclass can also be treated as an object of its superclass.

superclass services

In practice, subclasses should depend only on the "____" "____" (i.e., non-private methods) and not on the superclass data implementation.

hierarchical

In single inheritance, a class exists in a(n) "____" relationship with its subclasses

is-a

Objects of all classes that extend a common superclass can be treated as objects of that superclass—such objects have an "____" relationship with the superclass.

Package access

Protected members are said to have what type of access?

Inheritance

Reduces program-development time

super.

Subclass constructors can class superclass constructors via the "____" keyword

1. public 2. protected

Subclass methods can refer to ( public / protected / private ) members inherited from the superclass simply by using the member names. Choose two from the paren list.

Inheritance

Technique in which a new class is created by acquiring an existing class's members and possibly embellishing them with new or modified capabilities

direct superclass

The "_____" "_____" is the superclass from which the subclass explicitly inherits.

1. subclass 2. subclass

The 1.( subclass / superclass ) exhibits the behaviors of its 2.( subclass / superclass ) and can modify those behaviors so that they operate appropriately for the subclass.

specialization

The subclass exhibits the behaviors of its superclass and can modify those behaviors so that they operate appropriately for the subclass. This is why inheritance is sometimes referred to as "_____".

Single-inheritance relationships

These relationships form treelike structures -- a superclass exists in a hierarchical relationship with its subclasses

private members

These superclass members are hidden in its subclasses and can be accessed only through the public or protected methods inherited from the superclass.

protected members

These superclass members can be accessed by members of the superclass, by members of its subclasses, and by members of other classes in the *same package*.

@Overrride

This annotation indicates that a method should override a superclass method

super()

This is rarely done, but... When a *superclass* contains a no-argument constructor, you can use "____" to call that constructor *explicitly*

equals

This method compares two objects for equality and returns true if they're equal and false otherwise.

toString methods

This method is primarily a placeholder that can be overridden by a subclass to specify an appropriate String representation of the data in a subclass object.

toString

This method returns a String representation of an object

hashCode

This method uses int values used for high-speed storage and retrieval of information stored in a data structure that's known as a hashtable

finalize

This protected method is called by the garbage collector to perform termination housekeeping on an object just before the garbage collector reclaims the object's memory.

clone

This protected method, which takes no arguments and returns an Object reference, makes a copy of the object on which it's called.

has-a relationship

This relationship represents *composition*. In this relationship, an object contains as members references to other objects— e.g., a car has a steering wheel (and a car object has a reference to a steering-wheel object)

protected

Using "____" access offers an intermedi- ate level of access between public and private.

To call its direct superclass's constructor to ensure that the instance variables inherited from the superclass are initialized.

What is the first task of a subclass constructor?

implicitly

When an object is output using the %s format specifier, the objects toString method is called ( implicitly / explicitly ) to obtain its String representation.

constructor

When an object of a subclass is instantiated, a superclass "____" is called implicitly or explicitly

1. superclass 2. subclass

When creating a class, rather than declaring completely new members, you can designate that the new class should inherit the members of an existing class. The existing class is called the "___(1)___", and the new class is the "____(2)____".

To ensure that the instance variable inherited from the superclass are initialized properly

Why does Java require that the first task of any subclass constructor is to call its direct superclass's constructor, either explicitly or implicitly (if no constructor call is specified)?

To initialize the instance variables inherited from the superclass.

Why must each subclass constructor must implicitly or explicitly call one of its superclass's constructors?

Superclass

With inheritance, the instance variables and methods that are the same for all the classes in the hierarchy are declared in a ( subclass / superclass )

fragile or brittle

a class is said to be "____" or "____", because a small change in the superclass can "break" subclass implementation.

up

if the superclass is derived from another class, the superclass constructor invokes the constructor of the next class ( up / down ) the hierarchy, and so on.

Shallow Copy

instance-variable values in one object are copied into another object of the same type.

subclass

instantiating a ( subclass / superclass ) object begins a chain of constructor calls in which the subclass constructor, before performing its own tasks, explicitly uses super to call one of the constructors in its direct superclass or implicitly calls the superclass's default or no-argument constructor


Ensembles d'études connexes

personal finance literacy test module 3

View Set

Limits to Government Power Quick Check

View Set

Matura Repetytorium Poziom Rozszerzony - Wishes/Unreal Past

View Set

NCLEX Practice Questions: Renal, Nursing: Lines and Studies, Fluid and Electrolyte Review, LAB Values Aultman College, LEARN THIS ****

View Set