levo

Defining Data: Types, Variables and Classes

Declaring variables, scope and lifetime

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

Overview

Scope of a variable and variable shadowing.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is a constant, and how is a constant declared in Java?

Key term

What is variable shadowing, and how is a shadowed attribute reached in Java?

Key term

What two things must every variable declaration give?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a variable?

    Model answer

    A variable is a named area of memory that holds a value of a stated type and whose contents can change while the program runs.

  2. 2

    What two things must every variable declaration give?

    Model answer

    Every declaration must give the data type of the variable and the identifier by which the variable will be known.

  3. 3

    How does declaration differ from initialisation, using int count; and int count = 0; as the examples?

    Model answer

    The statement int count; declares the variable by reserving storage of that type, while int count = 0; also initialises it by placing a first value in that storage.

  4. 4

    What is an identifier, and what three rules must a legal Java identifier obey?

    Model answer

    An identifier is the name given to a variable, method or class; a Java identifier must not begin with a digit, must contain no spaces and must not be a reserved word.

  5. 5

    Why is the declaration int 2ndScore; rejected by the Java compiler?

    Model answer

    An identifier may not begin with a digit, because the compiler would otherwise be unable to tell the start of a name from the start of a number.

  6. 6

    What naming conventions apply to variables and to classes in Java?

    Model answer

    Java names variables and methods in camelCase, beginning with a lower-case letter as in numberOfPupils, and names classes in PascalCase, beginning with a capital as in BankAccount.

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