Chapter 9: Inheritance

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

What is an abstract class?

An abstract class is a class designed with implementation gaps for subclasses to fill in and is deliberately incomplete. It cannot be instantiated.

What is an abstract method?

An abstract method expects to be overriden in the class implementing it.

Class B inherits from class A. Describe the order in which the class's constructors execute when a class B object is created.

Constructor A first then B.

What is the superclass and what is the subclass in the following line? public class Pet extends Dog

Dog is superclass Pet is subclass

When you create a class, it automatically has a toString method and an equals method. Why?

It receives these methods from the Object class

How is an interface different from an abstract class, or any class?

Many interfaces can apply to many classes whereas an abstract class can only apply to a subclass

Can a subclass ever directly access the private members of its superclass

NO

What is the difference between overriding a superclass method and overloading a superclass method?

Overriding means that they have the same signatures in both methods. Overloaded methods have the same name, but different parameter lists.

In a subclass constructor, a call to the superclass constructor must

appear as the very first statement

this key word refers to an object's superclass

base

Abstract classes cannot

be instantiated

Fields in an interface are

both final and static

this key word indicates that a class inherits from another class

extends

If a subclass constructor does not explicitly call a superclass constructor, Java will not call any of the superclass's constructors

false

You can use a lambda expression to instantiate an object that

implements a functional interface

A method in a subclass having the same name as a method in the superclass but a different signature is an example of

overloading

Abstract methods must be

overridden

A method in a subclass that has the same signature as a method in the superclass is an example of

overriding

A subclass does not have access to these superclass members

private

these superclass members are accessible to subclasses and classes in the same package

protected

When a class implements an interface, it must

provide all of the nondefault methods that are listed in the interface, with the exact signatures and return types specified

Write the first line of a class named Employee, which implements an interface named Payable and Listable.

public class Employee implements Payable, Listable

in an inheritance relationship, this is the specialized class

subclass

The following is an inexplicit call to the supercalss's default constructor

super();

In an inheritance relationship, this is the general class.

superclass

The superclass constructor always executes before the subclass constructor

true

When a class contains an abstract method, the class cannot be instantiated

true

int k = a random number such that 1 k n; for (int p = 2; p <= k; p++) for (int r = 1; r < k; r++) System.out.println ("Hello"); What is the maximum number of times that Hello will be printed?

(D) (n-1)^2

What is the difference between a protected class member and a private class member?

A protected member can be accessed by other classes in the same package. A private member can only be accessed in the class where it is created.

When designing a class hierarchy, which of the following should be true of a superclass? A superclass should contain the data and functionality that are common to all subclasses that inherit from the superclass. A superclass should be the largest, most complex class from which all the other subclasses are derived. A superclass should contain the data and functionality that are only required for the most complex class. A superclass should have public data in order to provide access for the entire class hierarchy. A superclass should contain the most specific details of the class hierarchy.

A superclass should contain the data and functionality that are common to all subclasses that inherit from the superclass.

Here is the first line of a class declaration. What is the name of the superclass? What is the name of the subclass? public class Truck extends Vehicle

Vehicle is the superclass Truck is the subclass


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

World Civilization Chapter 6 Self Quiz

View Set