OCR A-Level Computer Science H446
Processors: Structure, Performance and Types
Input, Output and Storage
Systems Software
Applications Generation
Software Development
Types of Programming Language
Exchanging Data
Networks
Web Technologies
Data Types and Number Representation
Data Structures
Boolean Algebra
Legal, Moral, Cultural and Ethical Issues
Elements of Computational Thinking
Problem Solving and Programming
Algorithms
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.
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
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
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
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
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
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
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.
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.