OOP, Exceptions and Files

39 MCQs Covers classes, objects, init, self, access modifiers and exception handling. Also covers file modes, with open, unit testing and debugging

MCQs

39 questions · 35 min · 39 marks

Want to try first? Take the free Computer Science test: SDLC and Waterfall Model

Sample questions

The first 5 of 39. Try each one, then tap to see the answer.

  1. Question 1

    What is a class in Python?

    • AA set of if statements
    • BA blueprint to create objects
    • CA loop
    • DA function
    Show answer

    Answer: B

    A class defines the attributes and methods that its objects will have.

  2. Question 2

    Which method initializes a new object in Python?

    • Acreate
    • Bstart
    • Cnew
    • D__init__
    Show answer

    Answer: D

    __init__() is the constructor and runs automatically when an object is created.

  3. Question 3

    What does self refer to in a class?

    • AThe object itself
    • BThe current module
    • CA function
    • DA class variable
    Show answer

    Answer: A

    self refers to the current object and is used to access its attributes and methods.

  4. Question 4

    Which of the following defines inheritance?

    • AReusing variables
    • BAccessing files
    • COne class taking properties of another
    • DWriting the same function again
    Show answer

    Answer: C

    In inheritance a child class gets the properties and methods of a parent class.

  5. Question 5

    What is exception handling used for?

    • AMaking code faster
    • BManaging errors
    • CFixing bugs
    • DSaving files
    Show answer

    Answer: B

    It catches errors at run time so the program does not crash.

More tests in Python Programming

Practise with a free account

Save your scores, see which chapters need work, and keep a notebook of every question you got wrong.

Create free account