Coding | Mcqs | Multiple choice questions | Informative | Computer Science | Engineering | Aptitude | Quants | Verbal

INFEED

INFYTQ Screening Test 1.2

 

Session 1

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

class Test: def __init__(self): self.x = 0 class Test1(Test): def __init__(self): self.y = 1 def main(): b = Test1() print(b.x,b.y) main() 

 c. )  Error because class B inherits A but variable x isn’t inherited

2.Which of the following statements isn’t true?

 c.) The value of a private variable in the superclass can be changed in the subclass


3.)Output:

class A:

    def __init__(self):

        self._x = 5

class B(A):

    def display(self):

        print(self._x)

def main():

    obj = B()

    obj.display()

main()

Ans: C). 5

4.)What does built-in function type do in context of classes?

Ans: C)Determines class description of any value

5. What is the use of duck typing?

Ans: C) Less restriction on the type values that can be passed to a given method

6. What type of inheritance is illustrated in the following Python code?

class A():

    pass

class B():

    pass

class C(A,B):

    pass

Ans: B) Multiple Inheritance

7.What will be the output of the following Python code?

class Demo:

    def __init__(self):

        pass

    def test(self):

        print(__name__)

obj = Demo()

obj.test()

Ans:B.__main__

8.Which of the following statements is true? 

a)The new() method automatically invokes the init method 

b)The init method is dened in the object class 

c)The __eq(other) method is dened in the object class 

d)The repr() method is dened in the object class

Ans : c)The __eq(other) method is dened in the object class 

9.)What will be the output of the following Python code?

class A:

 def test(self):

 print("test of A called")

class B(A):

 def test(self):

 print("test of B called")

 super().test()

class C(A):

 def test(self):

 print("test of C called")

 super().test()

class D(B,C):

 def test2(self):

 print("test of D called")

obj=D()

obj.test()

Ans:A.) test of B called test of C called test of A called

10.)What will be the output of the following Python code?

class A:

    def __str__(self):

        return '1'

class B(A):

    def __init__(self):

        super().__init__()

class C(B):

    def __init__(self):

        super().__init__()

def main():

    obj1 = B()

    obj2 = A()

    obj3 = C()

    print(obj1, obj2,obj3)

main()

Ans : A) 1 1 1

11.)Which of the following is not a type of inheritance?

A) Double-level 

B)Multi-level 

C)Single-level 

D)Multiple

Ans: A) Double-level 

12.)What type of inheritance is illustrated in the following Python code?

class A():

    pass

class B():

    pass

class C(B):

    pass

Ans: A) Multi-level Inheritance

13.)All sub classes are a sub type in object-oriented programming. 

A)True 

B)False

Ans: B)False

14.)What does single-level inheritance mean? 

A)A subclass derives from a class which in turn derives from another class

B) A single superclass inherits from multiple subclasses 

C)A single subclass derives from a single superclass 

D)Multiple base classes inherit a single derived class

Ans: C)A single subclass derives from a single superclass 

15.)Which of the following statements is true? 

a)The new() method automatically invokes the init method 

b)The init method is dened in the object class 

c)The __eq(other) method is dened in the object class 

d)The repr() method is dened in the object class

Ans : c)The __eq(other) method is dened in the object class 

16)What will be the output of the following Python code?

class A:

    def __init__(self, x= 11):

        self.x = x

class der(A):

    def __init__(self,y = 22):

        super().__init__()

        self.y = y

def main():

    obj = der()

    print(obj.x, obj.y)

main()

Ans:D) 11 22

17)Which of the following best describes inheritance? 
A)Ability of a class to derive members of another class as a part of its own denition 
B)Means of bundling instance variables and methods in order to restrict access to certain class members C)Focuses on variables and passing of variables to functions 
D)Allows for implementation of elegant software that is well designed and easily modied

Ans:A)Ability of a class to derive members of another class as a part of its own denition 
18.)Suppose B is a subclass of A, to invoke the init method in A from B, what is the line of code you should write?
Ans: A) A.__init__(self)
19.)What will be the output of the following Python code?
class A():
    def fun(self):
        print("Python")
class B(A):
    pass
obj = B()
obj.fun()

Ans: D)Python
20.)What will be the output of the following Python code?
class A:
    def abc(self):
        return self.xyz()
    def xyz(self):
        return 'hello'
class B(A):
    def xyz(self):
        return 'maddy'
obj1=A()
obj2=B()
print(obj1.xyz(),obj2.xyz())

Ans: A)hello maddy

Session 2:

1-a
2-d
3-c
4-c
5+c
6+d
7+b
8+b
9+a
10+d

Session 3:

Problem 1:

Problem Statement Given a string S consisting of only '(' and ')', print 'yes' if it is balanced otherwise print 'no'. Input Format Enter a string S. Output Format Corresponding output.

Python Code solution: 
a=input().strip()
if(a.count('(')==a.count(')')):
  print("yes")
else:
  print("no")

Problem 2:

Problem Statement Given a string S,count the maximum number of times a character repeated in the string.If no character is repeated print '0'. Input Format Enter a string S. Output Format Corresponding output. Constraints 1 <= N <= 100000

Python Code solution: 
a=input().strip()
b=set(a)
c=0
for i in b:
  d=a.count(i)
  if(d>c+1):
    c=d
print(c)
***********************************THE END***********************************

Post a Comment

Previous Post Next Post