Skip to content

Commit 1c3d3d4

Browse files
committed
Create C04_p5.py
1 parent 637c55b commit 1c3d3d4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

C04/C04_p5.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#Create a class Publisher (name).
2+
#Derive class Book from Publisher with attributes title and author.
3+
#Derive class Python from Book with attributes price and no_of_pages.
4+
#Write a program that displays information about a Python book.
5+
#Use base class constructor invocation and method overriding.
6+
7+
class Publisher():
8+
9+
def __init__(self,t,n):
10+
self.__title=t
11+
self.__author=n
12+
def display(self):
13+
print("Title =",self.__title)
14+
print("author =",self.__author)
15+
class Book(Publisher):
16+
17+
def __init__(self,t,n,p,np):
18+
super().__init__(self,t,n)
19+
self.__price=p
20+
self.__no_of_page=np
21+
22+
def display(self):
23+
print("price =",self.__price)
24+
print("no_of_page =",self.__no_of_page)
25+
class Python(Book):
26+
def __init__(self,t,n,p,np):
27+
self.__title=t
28+
self.__author=n
29+
self.__price=p
30+
self.__no_of_page=np
31+
def display(self):
32+
print("Title =",self.__title)
33+
print("author =",self.__author)
34+
print("price =",self.__price)
35+
print("no_of_page =",self.__no_of_page)
36+
37+
obj =Python("book1","nam1",1000,100)
38+
obj.display()
39+

0 commit comments

Comments
 (0)