Computer Science With Python Chapter 3 Classes In Python
  • Sponsor Area

    NCERT Solution For Class 12 Computer And Communication Technology Computer Science With Python

    Classes In Python Here is the CBSE Computer And Communication Technology Chapter 3 for Class 12 students. Summary and detailed explanation of the lesson, including the definitions of difficult words. All of the exercises and questions and answers from the lesson's back end have been completed. NCERT Solutions for Class 12 Computer And Communication Technology Classes In Python Chapter 3 NCERT Solutions for Class 12 Computer And Communication Technology Classes In Python Chapter 3 The following is a summary in Hindi and English for the academic year 2021-2022. You can save these solutions to your computer or use the Class 12 Computer And Communication Technology.

    Question 1
    CBSEENCO12011539

    Define a class RING in Python with following specifications

    Instance Attributes
    - RingID 		# Numeric value with a default value 101
    - Radius 		# Numeric value with a default value 10
    - Area 			# Numeric value
    Methods:
    - AreaCal() 	# Method to calculate Area as
    				# 3.14*Radius*Radius
    - NewRing() 	# Method to allow user to enter values of
    				# RingID and Radius. It should also
    				# Call AreaCal Method
    - ViewRing() 	# Method to display all the Attributes 4

    Solution
    class RING: # OR class RING( ): OR class RING(Object):
    	def __init__(self):
    		self.RingID=101
    		self.Radius=10
    		self.Area=0
    	def AreaCal(self):
    		self.Area=3.14*self.Radius*self.Radius
    	def NewRing(self):
    		self.RingID=input('Enter RingID')
    		self.Radius=input('Enter radius')
    		self.AreaCal() # OR AreaCal(self)
    	def ViewRing(self):
    		print self.RingID
    		print self.Radius
    		print self.Area
    Question 2
    CBSEENCO12011540

    Differentiate between static and dynamic binding in Python? Give the suitable example of each.

    Solution


    Static Binding

    Dynamic Binding

    Time of binding

    happens during compilation

    binding happens at run time

    Actual object

    Actual object is not used for binding

    Actual object is used for binding

    Example

    Method overloading

    Method overriding

    Methods of binding

    Private, static and final methods show static binding. Because they cannot be overridden.

    Other than private, static and final methods show dynamic binding. Because they can be overridden.

    Class

    Type class

    Object class

    Question 3
    CBSEENCO12011541

    Write two methods in Python using the concept of Function Overloading (Polymorphism) to perform the following operations:
    (i) A function having one argument as side, to calculate Area of Square as side*side
    (ii) A function having two arguments as Length and Breadth, to calculate Area of Rectangle as Length*Breadth.

    Solution
    def Area(side):
    	print side*side
    def Area(length,breadth):
    	print length*breadth

    If you run the code, the second Area(B, H) definition will overwrite/override the first one because python does not support function overloading “ as illustrated in the example shown above ”.

    Question 4
    CBSEENCO12011585

    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.

    Solution

    (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

    Question 6
    CBSEENCO12011587

    Differentiate between static and dynamic binding in Python? Give suitable examples of each.

    Solution


    Static Binding

    Dynamic Binding

    Time of binding

    happens during compilation

    binding happens at run time

    Actual object

    Actual object is not used for binding

    Actual object is used for binding

    Example

    Method overloading

    Method overriding

    Methods of binding

    Private, static and final methods show static binding. Because they cannot be overridden.

    Other than private, static and final methods show dynamic binding. Because they can be overridden.

    Class

    Type class

    Object class

     
    Question 7
    CBSEENCO12011635

    What is the significance of super() method? Give an example of the same.

    Solution

    Super() function is used to call base class methods which have been extended in the derived class.
    Example-

    class GradStudent ( Student ):
    
    	def __init__ ( self ):
    		super ( GradStudent , self ). __init__ ()
    		self . subject = ''
    		self . working = ''
    	def readGrad ( self ):
    		# Call readStudent method of parent class
    		super ( GradStudent , self ). readStudent ()

    Question 8
    CBSEENCO12011636

    How do we implement abstract method in python? Give an example for the same.

    Solution

    Abstract method: An unimplemented method is called an abstract method. When an abstract method is declared in a base class, the derived class has to either define the method or raise 'NotImplementedError'.

    class Shape(object):
    	def findArea(self):
    		pass
    
    class Square(Shape):
    	def __init__(self,side):
    		self.side = side
    	def findArea(self):
    		return self.side * self.side

    Mock Test Series

    Sponsor Area

    Sponsor Area

    NCERT Book Store

    NCERT Sample Papers

    Entrance Exams Preparation

    37