Python OOP Fundamentals Quiz Quiz

  1. Class Definition Basics

    Which keyword is used to define a new class in Python?

    1. class
    2. def
    3. function
    4. newclass
    5. object
  2. Creating Objects

    How do you create an instance of a class named Animal?

    1. Animal[]
    2. Animal()
    3. new Animal
    4. Animal
    5. animal
  3. Object Attributes

    Given a Dog class with a 'name' attribute, how do you access the name of a dog object called pet?

    1. pet:name
    2. pet-name
    3. pet-u003Ename
    4. pet.name
    5. pet['name']
  4. The __init__ Method

    What is the special method in Python classes that initializes newly created objects?

    1. __new__
    2. __main__
    3. __init__
    4. __constructor__
    5. __start__
  5. Instance Methods

    In a Python class, what is the first parameter of an instance method typically named?

    1. myself
    2. obj
    3. self
    4. cls
    5. this
  6. Class vs Instance Variables

    Which variable is shared by all instances of a class?

    1. object variable
    2. member variable
    3. self variable
    4. instance variable
    5. class variable
  7. Inheritance Syntax

    How do you declare a class Car that inherits from Vehicle in Python?

    1. class Car extends Vehicle:
    2. class Car : Vehicle
    3. class Car(Vehicle):
    4. class Car-u003EVehicle:
    5. class Car =u003E Vehicle:
  8. Method Overriding

    If a subclass defines a method with the same name as one in its superclass, what happens?

    1. Both methods are called
    2. The subclass method overrides the superclass method
    3. SyntaxError occurs
    4. The subclass method is deleted
    5. The superclass method is ignored
  9. Polymorphism Illustration

    What is it called when different classes have methods with the same name that behave differently?

    1. Encapsulation
    2. Inheritance
    3. Abstraction
    4. Polymorphism
    5. Composition
  10. Encapsulation Purpose

    What does encapsulation refer to in object-oriented programming?

    1. Hiding internal data from outside access
    2. Inheriting from multiple classes
    3. Sharing methods with other classes
    4. Making attributes public
    5. Polymorphic method creation
  11. Private Attributes

    How do you indicate a private attribute named secret in a Python class?

    1. secret_
    2. private secret
    3. secret__
    4. __secret
    5. _secret
  12. Static Methods

    Which decorator is used to define a static method in a Python class?

    1. @staticmethod
    2. @static
    3. @classmeth
    4. @instancemethod
    5. @method
  13. Inheritance Benefit

    What is a main advantage of inheritance in Python?

    1. Private attribute access
    2. Increased memory usage
    3. Code reuse
    4. Syntax flexibility
    5. Slower execution
  14. Checking an Instance

    Given car = Car(), which function checks if car is an instance of Vehicle?

    1. issubclass(car, Vehicle)
    2. car.instanceOf(Vehicle)
    3. Vehicle.isInstance(car)
    4. isinstance(car, Vehicle)
    5. type(car, Vehicle)
  15. Multiple Inheritance

    How do you declare a Python class 'Hybrid' that inherits from 'Electric' and 'Gasoline'?

    1. class Hybrid extends Electric, Gasoline:
    2. class Hybrid(Electric, Gasoline):
    3. class Hybrid : Electric, Gasoline
    4. class Hybrid-u003EElectric, Gasoline:
    5. class Hybrid u003CElectric, Gasolineu003E: