Podcast
Questions and Answers
What is the general class in an inheritance relationship called?
What is the general class in an inheritance relationship called?
superclass
What is the specialized class in an inheritance relationship called?
What is the specialized class in an inheritance relationship called?
subclass
What key word indicates that a class inherits from another class?
What key word indicates that a class inherits from another class?
extends
What members of a superclass does a subclass not have access to?
What members of a superclass does a subclass not have access to?
What key word refers to an object's superclass?
What key word refers to an object's superclass?
In a subclass constructor, when must a call to the superclass constructor appear?
In a subclass constructor, when must a call to the superclass constructor appear?
What is the following an inexplicit call to the superclass's default constructor? super();
What is the following an inexplicit call to the superclass's default constructor? super();
What is it called when a method in a subclass has the same signature as a method in the superclass?
What is it called when a method in a subclass has the same signature as a method in the superclass?
What is it called when a subclass method has the same name as a method in the superclass but a different signature?
What is it called when a subclass method has the same name as a method in the superclass but a different signature?
What members of a superclass are accessible to subclasses and classes in the same package?
What members of a superclass are accessible to subclasses and classes in the same package?
When a class implements an interface, what must it provide?
When a class implements an interface, what must it provide?
What are fields in an interface?
What are fields in an interface?
Abstract methods must be what?
Abstract methods must be what?
What can abstract classes not do?
What can abstract classes not do?
You can use a lambda expression to instantiate an object that does what?
You can use a lambda expression to instantiate an object that does what?
If a subclass constructor does not explicitly call a superclass constructor, Java will not call any of the superclass's constructors.
If a subclass constructor does not explicitly call a superclass constructor, Java will not call any of the superclass's constructors.
The superclass constructor always executes before the subclass constructor.
The superclass constructor always executes before the subclass constructor.
When a class contains an abstract method, the class cannot be instantiated.
When a class contains an abstract method, the class cannot be instantiated.
What is the difference between a protected class member and a private class member?
What is the difference between a protected class member and a private class member?
What is the superclass and what is the subclass in the following line? public class Pet extends Dog
?
What is the superclass and what is the subclass in the following line? public class Pet extends Dog
?
Can a subclass ever directly access the private members of its superclass?
Can a subclass ever directly access the private members of its superclass?
What is the difference between overriding a superclass method and overloading a superclass method?
What is the difference between overriding a superclass method and overloading a superclass method?
What is an abstract method?
What is an abstract method?
What is an abstract class?
What is an abstract class?
What is the name of the superclass and the subclass in the following line? public class Truck extends Vehicle
?
What is the name of the superclass and the subclass in the following line? public class Truck extends Vehicle
?
Describe the order in which the class's constructors execute when a class B inherits from class A.
Describe the order in which the class's constructors execute when a class B inherits from class A.
When you create a class, why does it automatically have a toString method and an equals method?
When you create a class, why does it automatically have a toString method and an equals method?
How is an interface different from an abstract class, or any class?
How is an interface different from an abstract class, or any class?
Write the first line of a class named Employee, which implements an interface named Payable and Listable.
Write the first line of a class named Employee, which implements an interface named Payable and Listable.
When designing a class hierarchy, what should be true of a superclass?
When designing a class hierarchy, what should be true of a superclass?
Study Notes
Inheritance Basics
- Superclass is the general class in an inheritance relationship.
- Subclass is the specialized class that extends the functionality of the superclass.
- The keyword "extends" indicates that a class inherits from another class.
Access Modifiers in Inheritance
- Subclasses do not have access to private members of the superclass.
- Protected members of the superclass are accessible to subclasses and classes in the same package.
- Private members can only be accessed within the class where they are declared.
Class Constructors
- In a subclass constructor, a call to the superclass constructor must appear as the first statement.
- The call to the superclass's default constructor can be done using
super();
. - The superclass constructor always executes before the subclass constructor.
Method Overriding and Overloading
- A method in a subclass that has the same signature as a method in the superclass is an example of overriding.
- A method in a subclass with the same name but a different signature than a method in the superclass is an example of overloading.
- Overriding means the same signatures are present in both methods, while overloading has different parameter lists.
Abstract Classes and Methods
- Abstract methods must be overridden in the subclass implementing them.
- Abstract classes cannot be instantiated and are intentionally left incomplete for subclasses to fill in the gaps.
Interfaces
- When a class implements an interface, it must provide implementations for all non-default methods with exact signatures and return types.
- Fields in an interface are both final and static.
- An interface allows multiple interfaces to be applied across different classes, unlike abstract classes which relate to a single hierarchy.
Class Declaration and Members
- Constructors of superclass execute before those of the subclass when a subclass object is created.
- Class objects implicitly receive methods like
toString
andequals
from the Object class. - A subclass can never directly access the private members of its superclass.
Understanding Class Relationships
- In the declaration
public class Pet extends Dog
, Dog is the superclass and Pet is the subclass. - Abstract classes should encompass common functionality across subclasses, serving as a foundation for derived classes.
- An Employee class can implement multiple interfaces like Payable and Listable through the syntax
public class Employee implements Payable, Listable
.
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.
Description
Enhance your understanding of inheritance in object-oriented programming with these flashcards. Explore key terms such as 'superclass', 'subclass', and 'extends'. Perfect for anyone looking to solidify their knowledge in Chapter 9 of their programming course.