Skip to content
Question 94 of 97

Q.class Box: #Line 1 L = 10 #Line 2 Type="HARD" #Line 3 def init(self,T,TL=30): #Line 4 self.Type = T #Line 5 self.L = TL #Line 6 def Disp(self): #Line 7 print self.Type,Box.Type #Line 8 print self.L,Box.L #Line 9 B1=Box("SOFT",20) #Line 10 B1.Disp() #Line 11 Box.Type="FLEXI" #Line 12 B2=Box("HARD") #Line 13 B2.Disp() #Line 14 Write the output of the above Python code.

(OR)
class Target: #Line 1 def init(self): #Line 2 self.X = 20 #Line 3 self.Y = 24 #Line 4 def Disp(self): #Line 5 print self.X,self.Y #Line 6 def del(self): #Line 7 print "Target Moved" #Line 8 def One(): #Line 9 T=Target() #Line 10 T.Disp() #Line 11 One() #Line 12
(i) What are the methods/functions mentioned in Line 2 and Line 7 specifically known as?
(ii) Mention the line number of the statement, which will call and execute the method/function shown in Line 2.
Odisha ChseCBSE Class XII Board 2019Subjective· 2mImportance★★★★★est
97% · 94/97 Questions
🔒 Locked · start free trial →

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) traces instance vs class attributes to give the four printed lines; Part (b) identifies __init__/__del__ as constructor/destructor, the constructor being invoked at object creation on Line 10.

Part (a)

Box defines class attributes L = 10 and Type = "HARD". The constructor sets instance attributes self.Type = T and self.L = TL (default 30). Disp prints self.Type, Box.Type then self.L, Box.L.

  • B1 = Box("SOFT", 20) → self.Type="SOFT", self.L=20. B1.Disp():
    • self.Type, Box.Type → SOFT HARD
    • self.L, Box.L → 20 10
  • Box.Type = "FLEXI" changes the class attribute Type to "FLEXI".
  • B2 = Box("HARD") → TL takes default 30, so self.Type="HARD", self.L=30. B2.Disp():
    • self.Type, Box.Type → HARD FLEXI
    • self.L, Box.L → 30 10
SOFT HARD
20 10
HARD FLEXI
30 10 …

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.