Difference between Encapsulation and Abstraction
Encapsulation Abstraction
class Person: from abc import ABC, abstractmethod
def __init__(self): class Animal(ABC):
self.__age = 30 @abstractmethod
def make_sound(self):
pass
Difference between Constructor Overloading and Method Overloading
Constructor Overloading Method Overloading
class Example: class Calculator:
def __init__(self, a=None): def add(self, a, b=None):
if a: return a + b if b else a
print("Value is", a)
else:
print("No value")
Difference between Method Overloading and Operator Overloading
Method Overloading Operator Overloading
class Demo: class Vector:
def show(self, a=None): def __init__(self, x):
print(a if a else "No argument") self.x = x
def __add__(self, other):
return Vector(self.x + other.x)
Difference between Polymorphism and Inheritance
Polymorphism Inheritance
class Cat: class Animal:
def sound(self): def speak(self):
print("Meow") print("Animal sound")
class Dog: class Dog(Animal):
def sound(self): def speak(self):
print("Bark") print("Dog sound")
Difference between Compile-time and Run-time Polymorphism
Compile-time Polymorphism Run-time Polymorphism
class Area: class Shape:
def calc(self, a, b=None): def draw(self):
return a * a if b is None else a * b print("Drawing shape")
class Circle(Shape):
def draw(self):
print("Drawing circle")
Difference between Private and Protected
Private Protected
class Person: class Student:
def __init__(self): def __init__(self):
self.__salary = 10000 self._grade = 'A'
Difference between Function and Method
Function Method
def greet(): class Greet:
print("Hello!") def say_hello(self):
print("Hello!")
Difference between Constructor and Method
Constructor Method
class Car: class Car:
def __init__(self): def start(self):
print("Constructor called") print("Engine started")
Difference between Overloading and Overriding
Overloading Overriding
class Math: class Animal:
def add(self, a, b=None): def speak(self):
return a if b is None else a + b print("Animal sound")
class Cat(Animal):
def speak(self):
print("Meow")
Difference between Class and Method
Class Method
class Car: class Car:
def __init__(self, brand): def start_engine(self):
self.brand = brand print("Engine started")