levo

Fundamentals of Programming

Classes, Objects, Inheritance and Polymorphism

  • 3 things to know
  • Paper 1

Overview

Recall questions on classes, objects and instantiation, constructors, attributes and methods, encapsulation with getters and setters, inheritance and when to use it, overriding, and polymorphism.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Evaluation

Explain the advantages of the structured approach.

Key term

What is the difference between an attribute (property field) and a method?

Key term

What does a subclass inherit, and what can it do that its superclass cannot?

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 the methods and the property or attribute fields capturing the common behaviours and characteristics of a group of objects. It describes what any object of that kind will have and be able to do, but is not itself one of those objects. A class also acts as a data type, so variables can be declared of that class type.

  2. 2

    What is an object?

    Model answer

    A particular instance of a class, existing in memory while the program runs, with its own values in the attribute fields the class defines and able to carry out the methods the class defines. Many objects can be created from one class, each holding its own data.

  3. 3

    Distinguish between a class and an object, with an example.

    Model answer

    The class is the definition; the object is a thing made from it. A class Car might define attributes registration, make and mileage and methods start and service; the individual car with registration AB12 CDE is an object of that class. Changing that object's mileage affects only that object, whereas changing the class definition affects every object created from it. One class, any number of objects.

  4. 4

    What is instantiation?

    Model answer

    The process of creating an object from a class. Memory is allocated for the new object, a constructor is run to set up its initial attribute values, and a reference to the object is assigned to a reference variable of the class type, through which the object is then used.

  5. 5

    What is a constructor, and what is meant by an implicit and an explicit one?

    Model answer

    A constructor is the special method run automatically when an object is instantiated, whose job is to put the new object into a valid initial state. An explicit constructor is one the programmer writes, typically taking parameters so that initial attribute values can be supplied at creation. An implicit constructor is the default one the language supplies when none has been written, which creates the object with default attribute values.

  6. 6

    What is the difference between an attribute (property field) and a method?

    Model answer

    An attribute is a data item belonging to an object, describing a characteristic of it, such as a car's mileage. A method is a subroutine belonging to the class, defining a behaviour the object can perform, such as service, and it can read and change that object's attributes. A class definition consists of both.

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.

Fundamentals of Programming
Fundamentals of Data Structures
Fundamentals of Algorithms
Theory of Computation

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 driver is .
softwarehardwarestorage

Blank Blitz makes facts automatic

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

AThe integer 5 is 0101.
B0.75 is 1/2 + 1/4.
CThe fraction bits are 1100.

Build It gets the exam shape right

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

Head means the first single element of a non-empty list.
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 Fundamentals of Programming, 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.