1/70
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced | Call with Kai |
|---|
No analytics yet
Send a link to your students to track their progress
What is Polymorphism in Python?
It allows methods to have the same name but behave differently based on the object's context.
What are the two types of Polymorphism?
Compile-Time Polymorphism and Run-Time Polymorphism.
What is Compile-Time Polymorphism?
Determined during compilation, allowing methods or operators with the same name to behave differently based on input parameters.
What is Run-Time Polymorphism?
Determined during execution, occurs when a subclass provides a specific implementation for a method already defined in its parent class.
Provide an example of Run-Time Polymorphism.
Using a parent class Dog and subclasses Labrador and Beagle, each overriding the sound() method.
What is the purpose of the method sound() in the Dog class?
It provides a default implementation for the sound made by a dog.
What does the for loop do in the Run-Time Polymorphism example?
It iterates through each dog object and calls the appropriate sound() method based on the object type.
What is Compile-Time Polymorphism mimicked using in Python?
Using default arguments in method definitions.
What is Encapsulation?
The bundling of data (attributes) and methods within a class, restricting access to some components.
What are the types of Encapsulation?
Public Members, Protected Members, and Private Members.
What is the purpose of getters and setters in Encapsulation?
To control access and modification of private attributes.
What is Abstraction in OOP?
It hides internal implementation details while exposing only necessary functionality.
What are the types of Abstraction?
Partial Abstraction and Full Abstraction.
What is an Abstract Class?
A class that cannot be instantiated and is meant to be subclassed, containing at least one abstract method.
What is the role of the @abstractmethod decorator?
It indicates that a method must be implemented by any subclass of the abstract class.
What happens if a subclass does not implement an abstract method?
Python will raise an error and prevent the subclass from being instantiated.
What is a Concrete Method?
A method that has a complete implementation and can be used directly.
How does Python handle different types in a list?
Python treats them all as instances of the parent class.
What is the significance of using ABC in Python?
It allows the creation of abstract base classes, simplifying the use of abstract methods.

What does the method add() in the Calculator class demonstrate?
Compile-Time Polymorphism by allowing different numbers of arguments.
What is the output of calc.add(5, 10, 15)?
The output will be 30, as it sums all three arguments.
What is the purpose of the __init__ method in the Dog class?
To initialize the attributes of the Dog object.
What does the statement 'self.__age = age' in the Dog class signify?
It defines a private attribute that cannot be accessed directly outside the class.
What does the method get_info() in the Dog class return?
It returns a string containing the dog's name, breed, and age.
Why is the method sound() in the Dog class defined as abstract?
To enforce that all subclasses must provide their own implementation of the sound method.
What is the output of dog.get_age() if the dog's age is set to 5?
It returns the value 5, as it accesses the private attribute through the getter.
What does the statement 'dog.set_age(5)' do?
It modifies the private attribute __age to 5 if the value is valid.
What is the main goal of using OOP principles like Polymorphism, Encapsulation, and Abstraction?
To create a more modular, reusable, and maintainable code structure.
What is Object-Oriented Programming (OOP)?
A programming paradigm that uses 'objects' to represent data and methods, promoting reusable code.
What is the main difference between Object-Oriented Programming and Procedural-Oriented Programming?
OOP is a bottom-up approach focusing on objects, while Procedural Programming is a top-down approach focusing on functions.
What are the four main methodologies of OOP?
Inheritance, Polymorphism, Encapsulation, and Abstraction.
What is a class in Python?
A blueprint for creating objects, defining common attributes and behaviors.
How do you define a class in Python?
Using the 'class' keyword followed by the class name, e.g., 'class ClassName:'.
What are attributes in a class?
Characteristics defined within a class that describe the properties of an object.
What are methods in a class?
Functions defined inside a class that perform actions on objects.
What is an object in OOP?
A specific instance of a class.
How do you instantiate an object in Python?
By calling the class name followed by parentheses, e.g., 'object_name = ClassName()'.
What is a constructor in Python?
A special method called automatically when an object is created, used to initialize attributes.
What is the __init__ method?
The method that initializes a newly created instance of a class, commonly used as a constructor.
What is the __new__ method?
Responsible for creating a new instance of a class, allocating memory and returning the new object.
What is the difference between __init__ and __new__?
__new__ creates a new instance, while __init__ initializes the instance after it has been created.
What are access modifiers in OOP?
Keywords that set the visibility of class members, such as 'public', 'private', and 'protected'.
What is inheritance in OOP?
A mechanism where a new class derives properties and behavior from an existing class.
What is polymorphism in OOP?
The ability of different classes to be treated as instances of the same class through a common interface.
What is encapsulation in OOP?
The bundling of data and methods that operate on that data within one unit, restricting access to some components.
How do you define a method in a class?
By using the 'def' keyword followed by the method name and parameters, e.g., 'def method_name(self, parameters):'.
What is an example of a simple class in Python?
class Phone: def make_call(self): print('Making phone call')
How do you call a method from an object?
By using the syntax 'object_name.method_name()'.
What is the role of 'self' in class methods?
'self' refers to the instance of the class and is used to access variables and methods associated with the class.
What is the purpose of the __init__ method in a class?
It is called immediately after __new__ to initialize the created object.
What is a default constructor?
A constructor that does not take any parameters other than self and initializes the object with default attribute values.
What is a parameterized constructor?
A constructor that accepts arguments to initialize the object's attributes with specific values.
What is the syntax for defining a class in Python?
class ClassName: followed by methods and attributes.
What is the purpose of the self parameter in a method?
It refers to the instance of the class (object) itself, allowing access to its attributes.
What is inheritance in Object-Oriented Programming?
It is the transfer of characteristics from a parent class to a child class without modification.

What is single inheritance?
A derived class inherits characteristics from a single parent class.
What is multilevel inheritance?
A derived class inherits properties from an immediate parent class, which in turn inherits from its own parent class.
What is hierarchical inheritance?
More than one derived class inherits properties from a single parent class.
What is multiple inheritance?
A derived class inherits properties from more than one base class.
What does the super() function do?
It calls methods of a superclass from a subclass and returns a proxy object that delegates method calls to the superclass.
What are the key properties of a Vehicle class in the exercise?
vehicle_type, vehicle_name, no_of_tire.
What methods should the Vehicle class include?
A method to display all current values of the properties.
What is the purpose of creating an Animal class in the exercise?
To define at least 3 objects of type Animal with properties and methods.
What properties should the Bag class include?
size, color, noOfPockets.
What is the expected output of the methods in the classes created in the exercises?
Display all current values of the properties.
What is encapsulation in Object-Oriented Programming?
The bundling of data with the methods that operate on that data, restricting direct access to some of the object's components.
What is polymorphism in Object-Oriented Programming?
The ability of different classes to be treated as instances of the same class through a common interface.
What does the term 'abstraction' refer to in Object-Oriented Programming?
The concept of hiding the complex reality while exposing only the necessary parts.
What is the syntax for instantiating an object of a class?
object_name = ClassName(arguments).
What are the steps to create a child class in Python?
Create a parent class, define the init constructor, write methods for the parent class, create the child class, and instantiate the object.
What is the role of the display method in the classes created?
To show the current values of the properties defined in the class.