-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathoops.py
103 lines (68 loc) · 1.89 KB
/
oops.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
print()
print("Object Oriented Programming And Structure Learning")
print()
# class
class Student:
university_name = "OSGU"
def __init__(self,name,rollno,course):
self.name = name
self.rollno = rollno
self.course = course
def get_student_info(self):
print(self.name)
print(self.rollno)
print(self.course)
@staticmethod
def hello():
print("Hello EveryOne")
# object
ajay = Student("ajay",211020151006,"BCA")
aman = Student("aman",211020151001,"BCA")
print(ajay)
print(ajay.university_name)
ajay.get_student_info()
ajay.hello()
aman.get_student_info()
# Inheritance
class Car:
def __init__(self,name):
print("car constructor called....{}".format(name))
def __init__(self):
print("car constructor called....")
def start(self):
print("start car.")
print(self.name)
def stop(self):
print("stop car.")
class Tata(Car):
def __init__(self,name):
print("Tata Car contructor called.....")
self.name = name
print("\n\n")
tc1 = Tata("maruti800")
tc1.start()
tc1.stop()
from abc import ABC, abstractmethod
# Abstract class
class Shape(ABC):
@abstractmethod
def area(self):
pass # Subclasses must implement this method
@abstractmethod
def perimeter(self):
pass
# Concrete subclass
class Circle(Shape):
def __init__(self, radius):
self.radius = radius
def area(self):
return 3.14 * (self.radius ** 2) # Implementation of abstract method
def perimeter(self):
return 2 * 3.14 * self.radius
# Abstract classes cannot be instantiated directly
# shape = Shape() # This would raise an error
# Subclass instances are allowed
circle = Circle(5)
print("Area:", circle.area()) # Output: Area: 78.5
print("Perimeter:", circle.perimeter()) # Output: Perimeter: 31.4
s = Shape()