which piece of code creates an empty class?
class A:
return
class A:
pass
class A:
It is not possible to create an empty class.
SHOW ANSWERWhat are the methods which begin and end with two underscore characters called?
Special methods
In-built methods
User-defined methods
Additional methods
SHOW ANSWERWhat is the output of the following piece of code?
class stud:
def __init__(self,roll_no,grade):
self.roll_no=roll_no
self.grade=grade
def dislay(self):
print("roll no:",self.roll_no,"grade:",self.grade)
stud1=stud(34,'S')
stud1.age=7
print(hasattr(stud1,'age'))
Error as age isn't defined
True
False
7
SHOW ANSWERWhich of the following statements is wrong about inheritance?
Protected memebers of a class can be inherited
The inheriting class is called as a subclass
Private members of a class can be inherited and accessed
Inheritance is one of the features of oop
SHOW ANSWERWhat is the output of the following piece of code?
class A():
def disp(self):
print("A disp()")
class B(A):
pass
obj = B()
obj.disp()
Invalid syntax for inheritance
Error because when object is created, argument must be passed
Nothing is printed
A disp()
SHOW ANSWERWhat is the output of the following piece of code?
class A:
def one(self):
return self.two
def two(self):
return 'A'
class B(A):
def two(self):
return 'B'
obj1=A()
obj2=B()
print(obj1.two(),obj2.two())
AA
AB
BB
An exception is thrown
SHOW ANSWERWhat type of inheritance is illustrated in the following piece of code?
class A():
pass
class B(A):
pass
class C(B):
pass
Multi-level inheritance
Multiple inheritance
Hierarchical inheritance
Single-level inheritance
SHOW ANSWERWhat is the output of the following piece of code when executed in the Python shell?
class A:
pass
class B(A):
pass
obj=B()
print(isinstance(obj,A))
True
False
Wrong syntax for isinstance()method
Invalid method for classes
SHOW ANSWERThe assignment of more than one function to a particular operator is ---------
Operator over-assignment
Operator overriding
Operator overloading
Operator instance
SHOW ANSWERWhich of the following is not a class method?
Non-static
Static
Bounded
Unbounded
SHOW ANSWERWhich of the following best describes polymorphism?
Ability of a class to derive members of another class as a part of its own definition
Means of bundling instance variables and methods in order to restrict access to certain class members
Focuses on variables and passing of variables to functions
Allows for objects of different types and behaviour to be treated as the same general type
SHOW ANSWERA class in which one or more methods are only implemented to raise an exception is an abstract class. True or False?
True
False
SHOW ANSWEROverriding means changing behaviour of methods of derived class methods in the base class. Is the statement true or false?
True
False
SHOW ANSWER