B02B-2017D – Computer Sir Ki Class

Login


Lost your password?

Don't have an account ?
Register (It's FREE) ×
  

Login
[lwa]



Exam Questions-CBSE12D-2017-B02B #PYTHON#6407    siteicon   siteicon  

Problem Statement - B02B-2017D

class Test:
    rollno=1
    marks=75
    def __init__(self,r,m): #function 1
        self.rollno=r
        self.marks=m
    def assign(self,r,m): #function 2
        rollno = n
        marks = m
    def check(self): #function 3
        print self.rollno,self.marks
    print rollno,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.

Solution

TC++ #6407

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 rollno and marks.
ii)

Function 1       E1=Test(1,95)   # Any values in the parameter

Function 2      E1.assign(1,95)   # Any values in the parameter


Share

CSKC| Created: 12-Jan-2019 | Updated: 12-Jan-2019|CBSE12D-2017









Back