Session I - OOPs Concepts
Session I - OOPs Concepts
འཕེལ་ལྷན་ཁག།
Department of School Education
Ministry of Education & Skills Development
OOPs SESSION I
February 2023
Object Oriented Programming
(OOPs)
Content scope
Polymorphism
02 Method Overloading
Inheritance
03 Single level, Method overriding and Constructor
overriding
Competency
01
Explain the features of Object Oriented Programming
Objectives
02
Explain the components of a class with examples
Polymorphism Inheritance
Encapsulation Abstraction
Concept of Class, Attributes and Methods
class Dzong:
0 Attributes name=”Punakha”
01
01
1
Object 1t dzong1.Dzong()
Object 2t dzong2.Dzong()
Defining Class, Attributes, Methods
dzong_2=Dzong()
dzong_2.display_history()
Constructor (Instance Variable)-Parameterized
Sample
Code
class Dzong:
def__init__(self,name,location,built):
self.name=name
self.location=location
self.built=built
def display_history(self):
print(f"Name: {self.name}")
print(f"Location: {self.location}") Output
print(f"Year: {self.built}")
dzong=Dzong("Punakha","Bhutan",1637)
dzong.display_history()
dzong_1=Dzong("Tashichodzong","Bhutan",1629)
dzong_1.display_history()
Comparison(Default vs Parameterized)
Sample
Code
class Dzong: class Dzong:
def __init__(self): def__init__(self,name,location,built):
self.name="Punakha" self.name=name
self.location="Bhutan" self.location=location
self.year=1637 self.built=built
def display_history(self): def display_history(self):
print(f"Name: {self.name}") print(f"Name: {self.name}")
print(f"Location: {self.location}") print(f"Location: {self.location}")
print(f"Year: {self.year}") print(f"Year: {self.built}")
dzong_1=Dzong() dzong_1=Dzong("Punakha","Bhutan",1637)
dzong_1.display_history() dzong_1.display_history()
dzong_2=Dzong() dzong_2=Dzong("Tashichodzong","Bhutan",1629)
dzong_2.display_history() dzong_2.display_history()
Conclusion of constructor
Assignment
Activity 3: Task 3
Write a Python program to determine whether the student has passed or failed by
creating a class Student with attributes (name and marks)and relevant method(s).
Activity 3: Task 4:
Write a program to calculate the perimeter of a triangle by creating a class Triangle.
Days Program