levo

Types of Programming Language

Object-oriented programming: classes and objects, attributes and methods, encapsulation

  • 2 things to know
  • Component 01

Overview

Recall questions on classes, objects and instantiation, attributes and methods, encapsulation, getters and setters, and a concrete example of the problem encapsulation prevents.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is an attribute?

Key term

Explain the difference between an attribute and a method, and between a class and an object.

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a class?

    Model answer

    A template or blueprint that defines a type of object: it lists the attributes that every object of that type will have and defines the methods that can be carried out on them. A class is a definition, not a thing that exists while the program runs - defining a class Dog with attributes name and breed and a method bark creates no dog, it only says what a dog is.

  2. 2

    What is an object?

    Model answer

    A particular instance of a class, created while the program is running, with its own values for the attributes the class defines. Defining the class Dog costs no memory for a dog; creating the object myDog with name 'Rex' and breed 'collie' produces an actual dog in memory, separate from any other Dog object with its own name and breed.

  3. 3

    What is meant by instantiation?

    Model answer

    The act of creating an object from a class. Memory is allocated for the new object's attributes and a constructor method usually runs to set their starting values, so that a specific usable instance exists. Many objects can be instantiated from the same class, each independent of the others.

  4. 4

    What is an attribute?

    Model answer

    A data item belonging to an object, defining part of its state - what the object is like at this moment. A class BankAccount might define the attributes accountNumber, holderName and balance; each account object created from the class has its own values for those three, so changing one account's balance does not affect another's.

  5. 5

    What is a method?

    Model answer

    A subroutine defined inside a class that describes something an object of that class can do, or something that can be done to it. It normally operates on that object's own attributes. A BankAccount class might have methods deposit, withdraw and getBalance, so the behaviour that changes the balance lives with the balance itself.

  6. 6

    Explain the difference between an attribute and a method, and between a class and an object.

    Model answer

    An attribute is data the object holds - its state; a method is code the object can run - its behaviour. A class is the definition or template written by the programmer; an object is a specific instance of it that exists while the program runs. One class can produce many objects, each with the same attributes and methods but its own attribute values.

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.

Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation

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.

If it matches, the search .
succeedsfailsrestarts

Blank Blitz makes facts automatic

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

A0 + 0 gives 0.
B0 + 1 gives 1.
C1 + 1 gives 0 carry 1.

Build It gets the exam shape right

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

A global variable means a variable reachable from anywhere in the program.
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 Types of Programming Language, 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.