Class Definition Basics
Which keyword is used to define a new class in Python?
- class
- def
- function
- newclass
- object
Creating Objects
How do you create an instance of a class named Animal?
- Animal[]
- Animal()
- new Animal
- Animal
- animal
Object Attributes
Given a Dog class with a 'name' attribute, how do you access the name of a dog object called pet?
- pet:name
- pet-name
- pet-u003Ename
- pet.name
- pet['name']
The __init__ Method
What is the special method in Python classes that initializes newly created objects?
- __new__
- __main__
- __init__
- __constructor__
- __start__
Instance Methods
In a Python class, what is the first parameter of an instance method typically named?
- myself
- obj
- self
- cls
- this
Class vs Instance Variables
Which variable is shared by all instances of a class?
- object variable
- member variable
- self variable
- instance variable
- class variable
Inheritance Syntax
How do you declare a class Car that inherits from Vehicle in Python?
- class Car extends Vehicle:
- class Car : Vehicle
- class Car(Vehicle):
- class Car-u003EVehicle:
- class Car =u003E Vehicle:
Method Overriding
If a subclass defines a method with the same name as one in its superclass, what happens?
- Both methods are called
- The subclass method overrides the superclass method
- SyntaxError occurs
- The subclass method is deleted
- The superclass method is ignored
Polymorphism Illustration
What is it called when different classes have methods with the same name that behave differently?
- Encapsulation
- Inheritance
- Abstraction
- Polymorphism
- Composition
Encapsulation Purpose
What does encapsulation refer to in object-oriented programming?
- Hiding internal data from outside access
- Inheriting from multiple classes
- Sharing methods with other classes
- Making attributes public
- Polymorphic method creation
Private Attributes
How do you indicate a private attribute named secret in a Python class?
- secret_
- private secret
- secret__
- __secret
- _secret
Static Methods
Which decorator is used to define a static method in a Python class?
- @staticmethod
- @static
- @classmeth
- @instancemethod
- @method
Inheritance Benefit
What is a main advantage of inheritance in Python?
- Private attribute access
- Increased memory usage
- Code reuse
- Syntax flexibility
- Slower execution
Checking an Instance
Given car = Car(), which function checks if car is an instance of Vehicle?
- issubclass(car, Vehicle)
- car.instanceOf(Vehicle)
- Vehicle.isInstance(car)
- isinstance(car, Vehicle)
- type(car, Vehicle)
Multiple Inheritance
How do you declare a Python class 'Hybrid' that inherits from 'Electric' and 'Gasoline'?
- class Hybrid extends Electric, Gasoline:
- class Hybrid(Electric, Gasoline):
- class Hybrid : Electric, Gasoline
- class Hybrid-u003EElectric, Gasoline:
- class Hybrid u003CElectric, Gasolineu003E: