OOPs in Python MCQs Exercise I


Ques 1 OOPs


What is the output of the following Python Code?


class SmallCode:
    def __init__(self,name):
        self.name=name
    def show(self):
        print(self.name)
object=SmallCode("Vicky")
object.show()

  a) Vicky
  b) Error
  c) No output
  d) no 'name' variable is found


a is the correct option





Ques 2 OOPs


What is the output of the following Python Code?


class SmallCode:
    def __init__(self,name):
        self.name=name
    def show(self):
        print(self.name)
object=SmallCode()
object.show()

  a) Vicky
  b) Error
  c) No output
  d) no 'name' variable is found


b is the correct option





Ques 3 OOPs


What is the output of the following Python Code?


class smallcode:
    def __init__(self):
        self.sm= 'smallcode'
    def Change(self):
        sm='SM'
obJ=smallcode()
print(obj.sm)
obj.Change()
print(obj.sm)

  a) smallcode
  b) smallcode
smallcode
  c) error
  d) None of these


b is the correct option





Ques 4 OOPs


We can access a private variables outside the class?
  a) Yes
  b) No
  c) NA
  d) NA


b is the correct option





Ques 5 OOPs


We can access private variables outside the class in python.
  a) Yes
  b) No
  c) NA
  d) NA


a is the correct option





Ques 6 OOPs


What is the output of the following Python Code?


class SmallCode:
    def __init__(self,owner):
        self.owner = owner
object1=SmallCode("Vikas")
object1.yt="SmallCode"
object1.insta="SmallCode__"
print(len(object1.owner)+len(object1.__dict__))

  a) Error
  b) SmallCode
  c) 8
  d) None of these.


c is the correct option





Ques 7 OOPs


What is the output of the following Python Code?


class student:
    def __init__(self, roll_no,college):
        self.roll_no=roll_no
        self.college=college
    def display (self):
        print("Roll no : ", self.roll_no, ", Name: ",self.college)
student1 = student(18345354332,"PSIT COE")
student1.branch="Information Technology"
boolean=hasattr(student1, 'branch')
print(boolean)

  a) True
  b) False
  c) 18345354332
  d) PSIT COE


a is the correct option