levo

Defining Data: Types, Variables and Classes

Static variables in a class

  • 3 things to know
  • AS Unit 1

Overview

Static variable, static constant and static method.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is a static variable?

Key term

How does a static variable differ from an instance variable?

Key term

Why is a static variable normally accessed through the class name rather than through an object reference?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a static variable?

    Model answer

    A static variable is a variable declared as belonging to the class itself rather than to any object, so a single copy is shared by every object of that class.

  2. 2

    How many copies of a static variable exist, however many objects are created?

    Model answer

    Exactly one copy of a static variable exists, held with the class, no matter how many objects are created or whether any object exists at all.

  3. 3

    How does a static variable differ from an instance variable?

    Model answer

    A static variable is shared by the whole class and holds one value for all objects, whereas each object receives its own instance variable and can hold a different value in it.

  4. 4

    What are two realistic uses for a static variable?

    Model answer

    A static variable can count how many objects of a class have been created, and it can hold the next account number to be issued so that every object draws from one running source.

  5. 5

    class Account { static int count = 0; Account() { count++; } } — what is the value of Account.count after three objects have been created?

    Model answer

    The value of Account.count is 3, because the single shared counter starts at 0 and the constructor adds one to that same counter each of the three times an object is made.

  6. 6

    Why is a static variable normally accessed through the class name rather than through an object reference?

    Model answer

    A static variable belongs to the class, so using the class name makes clear that the value is shared and that no object is needed to reach it.

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 Defining Data: Types, Variables and Classes, 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.