← Back
Question 31 Interview Prep

What is self in Python?

self refers to the current instance of the class. It is used to access instance variables and methods inside the class.

Example:

class Student:

def __init__(self, name):
self.name = name

Here, self.name refers to the object's own variable.

Interview Tip:
A common answer interviewers expect is:

"self is used to represent the current object of the class."

Question 32 Interview Prep

What is inheritance in Python?

Inheritance is an OOP concept where one class acquires the properties and methods of another class. It promotes code reusability.

Example:

class Animal:

def sound(self):
print("Animal sound")


class Dog(Animal):
pass


dog = Dog()
dog.sound()

Here, the Dog class inherits from the Animal class.

Question 33 Interview Prep

What are the types of inheritance in Python?

Python supports multiple types of inheritance:

Single inheritance
Multiple inheritance
Multilevel inheritance
Hierarchical inheritance
Hybrid inheritance

Interviewers often ask this theoretical question in OOP rounds

Question 34 Interview Prep

What is polymorphism in Python?

Polymorphism means "many forms." It allows the same method or function name to behave differently depending on the object or situation.

Example:

class Dog:
def sound(self):
print("Bark")


class Cat:
def sound(self):
print("Meow")

Both classes use the same method name sound() but behave differently.

Question 35 Interview Prep

What is method overriding?

Method overriding occurs when a child class provides its own implementation of a method that already exists in the parent class.

Example:

class Animal:

def sound(self):
print("Animal sound")


class Dog(Animal):

def sound(self):
print("Bark")

Here, the Dog class overrides the sound() method.

Question 36 Interview Prep

What is encapsulation in Python?

Encapsulation is the process of wrapping data and methods together inside a class and restricting direct access to some data.

It helps protect data from accidental modification.

Example:

class BankAccount:

def __init__(self):
self.__balance = 1000

Variables with double underscore (__) are treated as private variables.

Question 37 Interview Prep

What is abstraction in Python?

Abstraction means hiding internal implementation details and showing only the essential functionality to the user.

It helps reduce complexity and improves code security.

Real-world example:
A user can drive a car without knowing how the engine works internally.

Question 38 Interview Prep

What is the difference between method overloading and method overriding?

Method overloading means creating multiple methods with the same name but different parameters.
Method overriding means redefining a parent class method inside the child class.

In Python:

Method overriding is fully supported.
Method overloading is achieved using default arguments.

Question 39 Interview Prep

What is the difference between instance variables and class variables?

Instance variables belong to individual objects, while class variables are shared among all objects of the class.

Example:

class Student:

school = "ABC School" # class variable

def __init__(self, name):
self.name = name # instance variable

Here:

school is shared by all objects
name belongs to each object separately

Question 40 Interview Prep

What is type casting in Python?

Type casting means converting one data type into another data type. Python provides built-in functions for type conversion such as int(), float(), and str().

Example:

num = "10"

converted_num = int(num)
print(converted_num)

Type casting is commonly used when handling user input or data processing.