QuesAns Print Page – CSKC
Sign In

Search

siteicon
Q&A CBSE12A-2017-B02B #6229

Question:

class Exam:
   Regno=1
   Marks=75
   def __init__(self,r,m): #function 1
       self.Regno=r
       self.Marks=m
   def Assign(self,r,m): #function 2
       Regno = r
       Marks = m
   def Check(self): #function 3
       print self.Regno, self.Marks
       print Regno, Marks

(i) In the above class definition, both the functions – function 1 as well
as function 2 have similar definition. How are they different in execution?
(ii) Write statements to execute function 1 and function 2.

Answer:

(i) Function 1 is the constructor which gets executed automatically as soon as
the object of the class is created. Function 2 is a member function which has
to be called to assign the values to Regno and Marks.
(ii) Function 1  E1=Exam(1,95) # Any values in the parameter
Function 2  E1.Assign(1,95) # Any values in the parameter