Inheritance in Java Programming

FuturisticIvory avatar
FuturisticIvory
·
·
Download

Start Quiz

Study Flashcards

16 Questions

When a Student object is instantiated, the default constructor of its superclass is invoked implicitly to do the necessary ______

initializations

To illustrate this, consider the following ______, public static void main( String[] args ){ Student anna = new Student(); }

code

The program flow of inheritance: The ______ keyword

super

A subclass can also explicitly call a constructor of its immediate ______

superclass

Few things to remember when using the ______ constructor call:

super

This is done by using the ______ constructor call

super

A super constructor call in the constructor of a subclass will result in the execution of relevant constructor from the ______, based on the arguments passed

superclass

For example, given our previous example classes Person and Student, we show an example of a ______ constructor call

super

The super() call MUST OCCUR AS THE ______ STATEMENT IN A CONSTRUCTOR

FIRST

The super() call can only be used in a ______ definition

constructor

In Java, all classes, including the classes that make up the Java API, are subclassed from the ______ superclass.

Object

A sample class hierarchy is shown below. Superclass - Any class above a specific class in the class ______.

hierarchy

Once a behavior (method) is defined in a superclass, that behavior is automatically inherited by all ______.

subclasses

A subclass only needs to implement the differences between itself and the ______.

parent

To derive a class, we use the ______ keyword.

extends

Suppose we have a parent class called ______.

Person

Study Notes

Object Instantiation and Inheritance

  • When a Student object is instantiated, the default constructor of its superclass is invoked implicitly to do the necessary initialization.
  • The program flow of inheritance is illustrated using the extends keyword.
  • A subclass can also explicitly call a constructor of its immediate superclass using the super keyword.

Super Constructor Call

  • A super constructor call in the constructor of a subclass will result in the execution of the relevant constructor from the superclass, based on the arguments passed.
  • The super() call must occur as the first statement in a constructor.
  • The super() call can only be used in a constructor definition.

Class Hierarchy

  • In Java, all classes, including the classes that make up the Java API, are subclassed from the Object superclass.
  • A superclass is any class above a specific class in the class hierarchy.
  • Once a behavior (method) is defined in a superclass, that behavior is automatically inherited by all subclasses.
  • A subclass only needs to implement the differences between itself and the superclass.

Class Derivation

  • To derive a class, we use the extends keyword.
  • Suppose we have a parent class called Person, and we can derive a subclass Student from it.

This quiz covers the concepts of inheritance in Java programming, including defining super classes and subclasses, overriding methods, and creating final methods and classes. It also discusses the Java class hierarchy and the Object superclass.

Make Your Own Quizzes and Flashcards

Convert your notes into interactive study material.

Get started for free
Use Quizgecko on...
Browser
Browser