Question 96 of 97
Q.Answer the questions
(i) to
(iii) based on the following: class Furniture(object): #Line 1 def init(self,Q): #Line 2 self.Qty = Q def GetMore(self,TQ): #Line 3 self.Qty =self.Qty+TQ def FRDisp(self): #Line 4 print self.Qty class Fixture(object): #Line 5 def init(self,TQ): #Line 6 self.Qty=TQ def GetMore(self,TQ): #Line 7 self.Qty =self.Qty+TQ def FXDisp(self): #Line 8 print self.Qty class Flat(Furniture,Fixture): #Line 9 def init(self,fno): #Line 10 self.Fno=fno Q=0 if self.Fno<100: Q=10 else: Q=20 Furniture.init(self,Q): #Line 11 Fixture.init(self,Q): #Line 12 def More(self,Q): #Line 13 Furniture.GetMore(self,Q) Fixture.GetMore(self,Q) def FLDisp(self): #Line 14 print self.Fno, Furniture.FRDisp(self) Fixture.FXDisp(self) FL=Flat(101) #Line 15 FL.More(2) FL.FLDisp()
(i) Write the type of the inheritance illustrated in the above.
(ii) Find and write the output of the above code.
(iii) What is the difference between the statements shown in Line 11 and Line 12?
(OR)
Define inheritance. Show brief python example of Single Level, Multiple and Multilevel Inheritance.
Puducherry CbseCBSE Class XII Board 2019Subjective· 4mImportance★★★★★est
99% · 96/97 Questions
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Part (a): the code shows multiple inheritance; tracing the object gives the output 101 24 then 24, and Lines 11/12 call the Furniture and Fixture constructors. Part (b): inheritance reuses a base class, illustrated with single-level, multiple and multilevel examples.
Part (a)
(i) class Flat(Furniture, Fixture) derives from two base classes -> Multiple Inheritance.
(ii) Trace:
FL = Flat(101)->Fno = 101; since101 < 100is False,Q = 20.Furniture.__init__(self, 20)setsself.Qty = 20;Fixture.__init__(self, 20)setsself.Qty = 20(the same instance attribute).FL.More(2)->Furniture.GetMore(self, 2)makesQty20 + 2 = 22, thenFixture.GetMore(self, 2)makesQty22 + 2 = 24.FL.FLDisp()runs three statements:print self.Fno,prints101and, because of the trailing comma, keeps the cursor on the same line.Furniture.FRDisp(self)runsprint self.Qty, printing24on that same line ->101 24.Fixture.FXDisp(self)runsprint self.Qty, printing24on the next line.
101 24
24
Watch out
Watch the trailing comma in print self.Fno,. In Python 2 it suppresses the newline, so the very next print (inside FRDisp) continues on the same line — that is why 101 and the first 24 appear together as 101 24, not on separate lines. …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.