levo

Objects, Classes and Data Structures

Inheritance and the base class

  • 3 things to know
  • AS Unit 1

Overview

Deriving one class from another, what a subclass inherits and what it does not, calling the base constructor, overriding a method, and the is-a test for deciding whether inheritance is the right relationship.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

Which Java keyword sets up inheritance?

Key term

Give the alternative names for the two classes in an inheritance relationship.

Key term

Which members of a base class does a subclass inherit, and which does it not?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is inheritance?

    Model answer

    Inheritance lets a new class take on the attributes and methods of an existing class and then add to or change what it needs, so shared code is written once and used many times.

  2. 2

    Which Java keyword sets up inheritance?

    Model answer

    Java writes inheritance with the keyword extends, as in class Manager extends Employee.

  3. 3

    Give the alternative names for the two classes in an inheritance relationship.

    Model answer

    The class being inherited from is called the base class, superclass or parent class, and the class inheriting from it is the derived class, subclass or child class.

  4. 4

    Which members of a base class does a subclass inherit, and which does it not?

    Model answer

    A subclass inherits the public and protected attributes and methods of its base class; constructors are not inherited, and private members exist in the object but cannot be named by the subclass.

  5. 5

    A class Employee holds name and pay, and Manager extends Employee and adds budget. What does one Manager object hold?

    Model answer

    A Manager object holds name, pay and budget together, because the object carries the base class attributes as well as those the subclass declares.

  6. 6

    What is the is-a test?

    Model answer

    The is-a test asks whether every object of the proposed subclass is genuinely a kind of the base class, and inheritance is only appropriate when the answer is yes.

Other ways to work this

The same content, four other ways.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A null is the of one.
absencepresencetype

Blank Blitz makes facts automatic

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

AA null means no value has been recorded.
BZero and an empty string are values.
CA null is the absence of a value.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Objects, Classes and Data Structures, on a schedule.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.