Chapter 10 inheritance

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

Protected class members are denoted in a UML diagram with the symbol

#

If a class contains an abstract method:

- you cannot create an instance of the class - the method will have only a header, but not a body, and end with a semicolon - the method must be overridden in subclasses

If two methods in the same class have the same name but different signatures, the second overrides the first.

False

In an inheritance relationship, the subclass constructor always executes before the superclass constructor.

False

Inheritance involves a subclass, which is the general class, and a superclass, which is the specialized class.

False

When an interface variable references an object, you can use the interface variable to call any and all of the methods in the class implementing the interface.

False

Look at the following code and determine what the call to super will do. public class ClassB extends ClassA { public ClassB() { super(10); } }

It will call the constructor of ClassA that receives an integer as an argument.

If a subclass constructor does not explicitly call a superclass constructor:

Java will automatically call the superclass's default or no-arg constructor just before the code in the subclass's constructor executes

If ClassA extends ClassB, then

Public members in ClassB are public in ClassA, but private members in ClassB cannot be directly accessed in ClassA

When a subclass extends a superclass, the public members of the superclass become public members of the subclass.

True

When an "is a" relationship exists between objects, it means that the specialized object has:

all the characteristics of the general object, plus additional characteristics

When a method is declared with the ________ modifier, it cannot be overridden in a subclass.

final

The super statement that calls the superclass constructor:

must be the first statement in the subclass's constructor

A subclass may call an overridden superclass method by:

prefixing its name with the super key word and a dot (.)

If a class contains an abstract method:

the method will have only a header, but not a body, and end with a semicolon

In a class hierarchy:

the more general classes are toward the top of the tree and the more specialized are toward the bottom

A protected member of a class may be directly accessed by:

methods of the same class methods of a subclass methods in the same package

Which of the following is TRUE about protected access?

Protected members may be accessed by methods in the same package or in a subclass, even when the subclass is in a different package.

Private members of the superclass cannot be accessed by the subclass.

True

All methods in an abstract class must also be declared abstract.

False

An anonymous inner class must:

implement an interface extend another class

Every class has a toString method and an equals method inherited from the Object class.

True

When one object is a specialized version of another object, there is this type of relationship between them.

is a

Every class is either directly or indirectly derived from the Object class.

True

It is not possible for a superclass to call a subclass's method.

True

If you do not provide an access specifier for a class member, the class member is given ________ by default.

package

Which of the following statements declares Salaried as a subclass of PayType

public class Salaried extends PayType

If a superclass does not have a default constructor or a no-arg constructor

then a class that inherits from it, must call one of the constructors that the superclass does have.

What key word can you use to call a superclass constructor explicitly?

super

If two methods have the same name but different signatures, they are

overloaded

All fields declared in an interface:

are final and static

In an interface all methods have

public access

This annotation tells the Java compiler that a method is meant to override a method in the superclass.

@Override

If ClassC extends ClassB, which extends ClassA, this would be an example of:

A chain of inheritance

When a subclass overloads a superclass method:

Both methods may be called with a subclass object

In the following statement, which is the subclass? public class ClassA extends ClassB implements ClassC

ClassA

In the following statement, which is the superclass? public class ClassA extends ClassB implements ClassC

ClassB

Given the following code which of the following is TRUE

ClassB must override each method in ClassA.

In the following statement, which is the interface? public class ClassA extends ClassB implements ClassC

ClassC

What is wrong with the following code? public class ClassB extends ClassA { public ClassB() { int init = 10; super(40); } }

The call to the method super must be the first statement in the constructor.

What is required for an interface method that has a body?

The method header must begin with the key word default.

Replacing inadequate superclass methods with more suitable subclass methods is known as what

Method overriding

Protected members are:

Not quite private; Not quite different

A subclass can directly access

Only public and protected members of the superclass

If a method in a subclass has the same signature as a method in the superclass, the subclass method overloads the superclass method.

False

In an inheritance relationship

The superclass constructor always executes before the subclass constructor

An abstract class is not instantiated, but serves as a superclass for other classes

True

In UML diagrams, inheritance is shown:

With a line that has an open arrowhead at one end that points to the superclass

Like a family tree, a ________ shows the inheritance relationship between classes.

class hierarchy

When declaring class data members, it is best to declare them as

Private members


Ensembles d'études connexes

power point lesson 4, 5, 6 and 7

View Set

INTB 3355 Exam 2 Clicker questions

View Set

Personal Finance - Chapter 3 Review

View Set