¡GoConqr estrena diseño! Cuéntanos qué te parece.

Test

OOPs Concept in Python Quiz 2

PathaPadha Support 14 preguntas

Hacer el test

Este test tiene tiempo límite, así que se abre en el reproductor de siempre.

Preguntas del test (14)

  1. 1What will be the output of the following code?

    class Test:
    def __init__(self, s):
    self.s = s

    def print(self):
    print(s)

    a = Test("Python Class")
    a.print()
    1. AThe program gives an error because there is no constructor for class Test.
    2. BSignature for the print method is incorrect, so an error is thrown.
    3. CThe above code will execute correctly on changing print(s) to print(self.s).
  2. 2What will be the output of the following code?

    class Test:
    def __init__(self, s):
    self.s = s

    def print(self):
    print(self.s)

    msg = Test()
    msg.print()
    1. AThe program has an error because class Test does not have a constructor.
    2. BThe above code produces an error because the definition of print(s) does not include .
    3. CIt executes successfully but prints nothing.
    4. DThe program has an error because of the constructor call is made without an argument.
  3. 3What will be the output of the following code?

    class Test:
    def __init__(self, s = "Welcome"):
    self.s = s

    def print(self):
    print(self.s)

    msg = Test()
    msg.print()
    1. AThe program has an error because the constructor is not present in class Test.
    2. BThe above code produces an error because the definition of print(s) does not contain .
    3. CIt executes successfully but prints nothing.
    4. DThe program has an error because of the constructor call is made without an argument.
    5. EThe program executes successfully and prints Welcome.
  4. 4What will be the output of the following code snippet?

    class Test:
    def __init__(self):
    self.x = 1
    self.__y = 1

    def getY(self):
    return self.__y

    val = Test()
    print(val.x)
    1. AThe program has an error because x is private and cannot be accessed outside of the class.
    2. BThe program has an error because you cannot name a variable using .
    3. CThe program runs fine and prints 1.
    4. DThe program runs fine and prints nothing.
  5. 5What will be the output of the following code snippet?

    class Test:
    def __init__(self):
    self.x = 1
    self.__y = 1

    def getY(self):
    return self.__y

    val = Test()
    print(val.__y)
    1. AThe program has an error because y is private and should not access it from outside the class.
    2. BThe program has an error because you cannot name a variable using __y.
    3. CThe program runs fine and prints 1.
    4. DThe program runs fine and prints nothing.
  6. 6What will be the output of the following code snippet?

    class Test:
    def __init__(self):
    self.x = 1
    self.__y = 1

    def getY(self):
    return self.__y

    val = Test()
    val.x = 45
    print(val.x)
    1. AThe program has an error because x is private and should not access it from outside the class.
    2. BThe program has an error because you cannot name a variable using __y.
    3. CThe program runs fine and prints 1.
    4. DThe program runs fine and prints 45.
  7. 7Which of the following is a private data field in the given code snippet?

    class Test:
    def __init__(self):
    __a = 1
    self.__b = 1
    self.__c__ = 1
    __d__ = 1
    1. A__a
    2. B__b
    3. C__c__
    4. D__d__
  8. 8What will be the output of the following code snippet?

    class Test:
    def __init__(self):
    self.x = 1
    self.__y = 1

    def getY(self):
    return self.__y

    val= Test()
    val.__y = 45
    print(val.getY())
    1. AThe program has an error because y is private and should not access it from outside the class.
    2. BThe program has an error because you cannot name a variable using __y.
    3. CThe code runs fine and prints 1.
    4. DThe code executes successfully and prints 45.
  9. 9What will be the output of the following code snippet?

    def main():
    myCounter = Counter()
    num = 0

    for i in range(0, 100):
    increment(myCounter, num)

    print("myCounter.counter =", myCounter.counter, ", number of times =", num)

    def increment(c, num):
    c.counter += 1
    num += 1

    class Counter:
    def __init__(self):
    self.counter = 0

    main()
    1. Acounter is 101 , number of times is 0
    2. Bcounter is 100, number of times is 0
    3. Ccounter is 100, number of times is 100
    4. Dcounter is 101, number of times is 101
  10. 10What code can we put at the third line of the definition of class B to invoke its superclass’s constructor?

    class A:
    def __init__(self, i = 1):
    self.i = i

    class B(A):
    def __init__(self, j = 2):
    ___________________
    self.j = j

    def main():
    b = B()
    print(b.i, b.j)

    main()
    1. Asuper().__init__(self)
    2. Bsuper().__init__()
    3. CA.__init__()
    4. DA.__init__(self)

Información

Descripción
Coding Python Test sobre OOPs Concept in Python Quiz 2, creado por PathaPadha Support el 27/10/2020.
Idioma
English
Visitas
154
Etiquetas
pythoncoding
Valoración
Aún sin valoraciones
Valora este test
Valora este test

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?