JAVA inheritance (last quiz)

Ace your homework & exams now with Quizwiz!

Which of the following is correct?

A base class is a parent class or super class.

Which of the following is TRUE about Java classes?

All classes must have one parent but may have any number of children (derived or extended).

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

F

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

F

Assume that Poodle is a derived class of Dog and that Dog d = new Dog(...) and Poodle p = new Poodle(...) where the ... are the necessary parameters for the two classes. The assignment statement p = d; is legal even though d is not a Poodle?

F A wider object reference cannot be assigned to narrower reference. P is narrower since it is more specific then d.

The instruction super(); does which of the following?

It calls the constructor as defined in the current class's parent class. The instruction super(); represents an invocation of something in the current class's parent class. Since there is no message but merely super(), it is an invocation of the parent class's constructor.

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

The ________ key word is used to call a superclass constructor explicitly.

Super

Because every class directly or indirectly inherits from the Object class, every class inherits the Object class's members.

T

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

T

Example Code Ch 09-1 Consider the following class hierarchy: X | | | Y. Z | |. | A B Refer to Example Code Ch 09-1: If A, B, Y and Z all contain the same instance data d1, then d1 should be declared in X and inherited into Y, Z, A and B.

T Anything in common between A, B, Y and Z should be declared in X to properly identify that it is a class trait common amongst them. That is, common elements should be defined as high up in the hierarchy as possible. If all descendants of X have the trait (instance data) d1, then it is part of X too.

When a subclass overloads a superclass method ________.

both methods may be called with a subclass object

Inheritance through an extended (derived) class supports which of the following concepts?

code reuse By extending a class and inheriting from it, the new class does not have to reimplement any of those inherited methods or instance data, thus saving the programmer time and effort. So, code reuse is the ability to reuse someone else's code for your benefit by extending it for your needs.

A subclass may call an overridden superclass method by ________.

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

Java does not support multiple inheritance but some of the abilities of multiple inheritance are available by

implementing interfaces Since a class can implement any number of interfaces, that class is in essence using the interface classes as if those interfaces were defined in this class. So this class is inheriting the methods and constants of the interfaces. Further, the class could extend another class and thus inherit directly and indirectly from multiple classes. This is not the exact same as multiple inheritance, but it is as close as Java comes to that concept.

Aside from permitting inheritance, the visibility modifier protected is also used to

permit access to the protected item by any class defined in the same package The visibility modifier protected is used to control access to the item in a protected (guarded) manner. The protection is that access is restricted to the current class (like private items), classes in the same package, or extended classes of this class.


Related study sets

Philosophy Quiz Questions (FINAL pt.1)

View Set

The Enlightenment and The Scientific Revolution

View Set

Immunology Exam 1 MC, T/F Quiz Questions

View Set

Chapter 1 Environmental Problems, Their Causes, and Sustainability

View Set

New English Adventure 2 - Unit Hello

View Set

Language: What Develops in the First Two Years?

View Set

Ch. 48 Skin Integrity and Wound Care

View Set

264- Binary, HEX & ASCII Study Guide- Quiz Questions-Spiker.J

View Set