Chapter 10: Programming Quiz

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

Does the "super" key word work only with the superclass constructors? Please explain.

The "super" keyword can be used to call the superclass constructors and can also be used to access superclass members.

What is a method signature?

The method's signature consists of the method's name and the data type of the methods parameters in the order that they appear.

Describe the placement of more general and more specialized classes in a class hierarchy.

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

In an inheritance relationship, this is the specialized class.

The subclass

In an inheritance relationship, this is the general class.

The superclass

What are the "superclass" and "subclass"?

The superclass is the general class and the subclass is the specialized class. The subclass inherits fields and methods form the superclass without any of them having to be rewritten. New fields and methods may be added to the subclass to make it a specialized version of the superclass.

What is "overriding" ?

The term overriding is when the subclass replaces inadequate super class methods with more suitable once.

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

This key word refers to an object's superclass

super

The following is an explicit call to the superclass's default constructor.

super();

What is a class hierarchy?

A graphical representation of inheritance relationships between classes.

How can you prevent a method from being overridden?

Add the "final" modifier to the method header.

What is "Inheritance"?

Inheritance allows a new class to extend an existing class. The new class inherits the members of the class it extends.

To what does the "super" key word refer?

It refers to the object's superclass

What is the @Override annotation and why is it a good idea to use it?

It tells the compiler that a method is intended to override a superclass method. It is a good idea to use it so that any errors in properly overriding the method are displayed.

Summarize the three guidelines for calling a superclass constructor.

1. The super constructor may only be called in a subclass constructor. 2. The super statement that calls the superclass constructor must be called on the first line. 3. If the subclass constructor does not explicitly call the superclass constructor, Java will automatically call the default or no-arg constructor before the sub-class constructor.

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

Appear as the very first statement

Why should you avoid making class members protected when possible?

Because any other class that inherits from the class, or is in the same package, has unrestricted access to the protected member.

Can a superclass access members of a subclass?

No

What is the difference between "Overriding" and "Overloading" a method?

Overloaded methods have the same name but different signatures. Overridden methods both have the same signature.

What is the difference between private members and protected members?

Private members may be accessed only by methods in the same class. A protected member of a class may be directly accessed by methods of the same class or methods of a subclass. In addition, protected members may be accessed by methods of any class that are in the same package as the protected member's class.

What is the difference between private access and package access?

Private members may be accessed only by methods in the same class. Any method in the same package as the class may directly access the class's members that have package access.

When a class member is declared as protected, what code may access it?

Protected members of class may be accessed by methods in a subclass, and by methods in the same package as the class.

Why would a superclass need a no-arg constructor?

So that the constructor can be called automatically whenever a subclass is created.

Describe the "Is a" relationship.

When one object is a specialized version of another object, there is an "is a" relationship between them.

Why is it easy to give package access to a class member by accident?

When you accidentally leave out the access specifier, the member will have package access.

Can a subclass access members of a superclass?

Yes

This key word indicates that a class inherits from another class.

extends


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

Chapter 18: Aldehydes and Ketones - Nucleophilic Addition to the Carbonyl Group

View Set

Anatomy lecture quiz ( Nervous system)

View Set

Comprehensive Review Saunders Hesi based questions

View Set