Page 362 - C++
P. 362

CBSE AISSCE 2017-2018 Marking Scheme for Computer Science
                                       (2018-2019 Sub Code: 083       Paper Code: 91)

                                         print self,name, self.Age
                          class student(person):
                                 def __init__(self,name,age,rollno,marks):
                                         super(student,self)._init_(self, name, age)

                                         self.rollno=rollno
                                         self.marks=marks
                                 def getRoll(self):
                                         print self.rollno, self.marks

                          (1 mark for mentioning the advantage, 1 mark for writing any suitable
                          example)

                     (b)  class Vehicle:                        #Line 1                                        2
                              Type = 'Car'                      #Line 2
                              def __init__(self, name):         #Line 3
                                  self.Name = name              #Line 4
                              def Show(self):                   #Line 5
                                  print self.Name,Vehicle.Type  #Line 6


                          V1=Vehicle("BMW")                     #Line 7
                          V1.Show()                             #Line 8
                          Vehicle.Type="Bus"                    #Line 9
                          V2=Vehicle("VOLVO")                   #Line 10
                          V2.Show()                             #Line 11

                     (i)   What is the difference between the variable in Line 2 and Line 4 in the above
                          Python code?

                    Ans  The variable in Line 2 is a class attribute. This belongs to the class itself.
                          These attributes will be shared by all the instances.
                          The variable in Line 4 is an instance attribute. Each instance creates a
                          separate copy of these variables.

                          (1 mark for correct difference)

                     (ii)  Write the output of the above Python code.

                    Ans  BMW Car
                          VOLVO Bus

                          (½ for writing each correct line of output)

                     (c)  Define a class CONTAINER in Python with following specifications                     4

                          Instance Attributes
                          - Radius,Height   # Radius and Height of Container
                          - Type            # Type of Container
                          - Volume          # Volume of Container


                                                        Page #20/35
   357   358   359   360   361   362   363   364   365   366   367