levo

Objects, Classes and Data Structures

Overloading methods

  • 3 things to know
  • AS Unit 1

Overview

Method overloading, key difference between overloading and overriding and risk of overloading a method with very similar parameter lists.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is method overloading?

Key term

At what point is the choice between overloaded methods made?

Key term

A class Rectangle offers both Rectangle(double w, double h) and Rectangle(double side). What is the second constructor for?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is method overloading?

    Model answer

    Method overloading is declaring several methods in one class that share a name but differ in the number, types or order of their parameters.

  2. 2

    Why is overloading useful to the programmer calling the class?

    Model answer

    Overloading lets one sensible name cover the same operation applied to different kinds or amounts of data, so the caller does not have to remember a separate name for each case.

  3. 3

    Which part of a method must differ for two methods to be overloaded?

    Model answer

    The parameter list must differ, because the compiler tells overloaded methods apart by the number, the types and the order of their parameters.

  4. 4

    Can two methods be overloaded on their return type alone?

    Model answer

    Two methods that differ only in return type cannot be overloaded, because a call written on its own gives the compiler nothing by which to choose between them.

  5. 5

    At what point is the choice between overloaded methods made?

    Model answer

    The choice is made by the compiler from the types of the arguments written in the call, before the program is ever run.

  6. 6

    A class Printer declares show(int n), which prints the word whole, and show(double n), which prints the word decimal. What does the call show(5); print?

    Model answer

    The call prints whole, because the literal 5 is an int and the compiler prefers the exact int match to widening the value into a double.

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.