levo

Objects, Classes and Data Structures

Overloading methods

  • 3 things to know
  • AS Unit 1
Start revising · £5/month

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.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

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

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A null is the of one.
absencepresencetype

Blank Blitz consolidates the facts

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

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

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.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

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