levo

Types of Programming Language

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

  • 2 things to know
  • Component 01
Start revising · £5/month

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.

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.

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

Cram the night before, weakest topic first

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

If it matches, the search .
succeedsfailsrestarts

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.

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