Podcast
Questions and Answers
An object of a derived class has the type of the derived class, and it also has the type of the base class, and more generally, has the type of every one of its ___________ classes.
An object of a derived class has the type of the derived class, and it also has the type of the base class, and more generally, has the type of every one of its ___________ classes.
ancestor
Overriding is when a derived class redefines a method from the base class.
Overriding is when a derived class redefines a method from the base class.
True (A)
If an instance variable is not modified by public, protected or private then it is said to have:
If an instance variable is not modified by public, protected or private then it is said to have:
- Package access
- Default access
- Friendly access
- All of the above (correct)
Inheritance is the process by which a new class - known as a _________ - is created from another class, called the _____________.
Inheritance is the process by which a new class - known as a _________ - is created from another class, called the _____________.
When a class both extends and implements, by convention the ____ clause is last in the class header.
When a class both extends and implements, by convention the ____ clause is last in the class header.
A constructor for a derived class begins with an invocation of a constructor for the base class.
A constructor for a derived class begins with an invocation of a constructor for the base class.
Inheritance refers to a very specialized form of a class.
Inheritance refers to a very specialized form of a class.
A(n) ____ is not an object, but it points to a memory address.
A(n) ____ is not an object, but it points to a memory address.
A derived class contains only public instance variables and public methods from the base class.
A derived class contains only public instance variables and public methods from the base class.
The call to the base class constructor (super) must always be the last action taken in a constructor definition.
The call to the base class constructor (super) must always be the last action taken in a constructor definition.
When you define a class, if you do not explicitly extend another class, your class is an extension of the ____ class.
When you define a class, if you do not explicitly extend another class, your class is an extension of the ____ class.
A derived class is a class defined by adding instance variables and methods to an existing class.
A derived class is a class defined by adding instance variables and methods to an existing class.
In using the keyword this in place of super(), the invocation of this must be the ___________ action taken by the constructor.
In using the keyword this in place of super(), the invocation of this must be the ___________ action taken by the constructor.
You may substitute the keyword this for super() to call a constructor of the derived class.
You may substitute the keyword this for super() to call a constructor of the derived class.
When you assign a variable or constant of one type to a variable of another type, the behavior is called ____.
When you assign a variable or constant of one type to a variable of another type, the behavior is called ____.
A(n) ____ class is one from which you cannot create any concrete objects, but from which you can inherit.
A(n) ____ class is one from which you cannot create any concrete objects, but from which you can inherit.
If the final modifier is added to the definition of a method, this means:
If the final modifier is added to the definition of a method, this means:
A good toString() method can be very useful in debugging a program.
A good toString() method can be very useful in debugging a program.
The equals method for a class should have _________ as the type of its one parameter.
The equals method for a class should have _________ as the type of its one parameter.
If Java did not allow you to ____ classes, you would need to create every part of a program from scratch.
If Java did not allow you to ____ classes, you would need to create every part of a program from scratch.
If you do not specify a package for a class, it is placed in an unnamed ____ package.
If you do not specify a package for a class, it is placed in an unnamed ____ package.
The following statement creates an array of three Animal references.
The following statement creates an array of three Animal references.
Private methods of the base class are not available for use by derived classes.
Private methods of the base class are not available for use by derived classes.
The special syntax for invoking a constructor of the base class is:
The special syntax for invoking a constructor of the base class is:
When a class both extends and implements, by convention the ____ clause is last in the class header.
When a class both extends and implements, by convention the ____ clause is last in the class header.
An instance variable (or method) that is private in a base class is accessible by name in the definition of a method in any other class.
An instance variable (or method) that is private in a base class is accessible by name in the definition of a method in any other class.
Inheritance promotes code ___________.
Inheritance promotes code ___________.
A derived class is also called a ___ class.
A derived class is also called a ___ class.
The class __________ is an ancestor class of all Java classes.
The class __________ is an ancestor class of all Java classes.
An application's ability to select the correct subclass method is known as ____.
An application's ability to select the correct subclass method is known as ____.
The Object class contains the method:
The Object class contains the method:
A base class is synonymous with a:
A base class is synonymous with a:
A super class is also called a:
A super class is also called a:
Flashcards are hidden until you start studying
Study Notes
Inheritance Basics
- An object of a derived class has types of the derived class, base class, and all ancestor classes.
- Inheritance creates a new class, known as a derived class, from an existing class called the base class.
Method Overriding
- Overriding occurs when a derived class redefines a method from its base class.
- Derived classes can also add instance variables and methods to enhance the base class functionality.
Access Modifiers
- If an instance variable lacks public, protected, or private modifiers, it has package access, also termed default or friendly access.
Class Relationships
- A derived class is referred to as a subclass, while a base class is synonymous with the parent class or superclass.
- The Object class is the ancestor of all Java classes, automatically extending from it if no other superclass is specified.
Constructor Behavior
- A constructor in a derived class starts by invoking a constructor of its base class, although this invocation doesn't have to be the last action taken.
Object References
- A reference is not an object but points to a memory address where an object is stored.
Abstract and Final Classes
- An abstract class cannot instantiate objects but can serve as a base for other classes.
- A method defined with the final modifier cannot be redefined in any derived class.
Debugging and Utility Methods
- Implementing a robust toString() method aids significantly in debugging Java programs.
- The equals method in a class should have Object as the parameter type.
Dynamic Binding
- The capability of selecting the appropriate subclass method at runtime is termed dynamic method binding.
Accessing Methods and Variables
- Private methods in a base class are inaccessible to derived classes.
- An instance variable or method declared private is not accessible by name in other class methods.
Code Reusability
- Inheritance encourages code reuse, allowing shared functionality without rewriting code.
Array and Package Defaults
- Creating an array of Animal references can be done as:
Animal[] ref = new Animal;
. - Classes without a specified package belong to the unnamed default package.
Calling Superclass Constructors
- Superclass constructors are invoked using the syntax
super()
, which allows for proper initialization in inheritance hierarchies.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.