Exam PCAP All QuestionsBrowse all questions from this exam
Question 69

A class constructor (Choose two.)

    Correct Answer: B, C

    A class constructor cannot be invoked directly from inside the class. This means that constructors are special methods used to initialize objects and are usually called when an object is created. Additionally, a class constructor can be invoked directly from any of the subclass. Subclasses can access and call superclass constructors to ensure proper initialization of inherited attributes.

Discussion
SenthorusOptions: BC

I think it's true

Mikku123Options: BD

B & D.

kstrOptions: AC

The correct options are: A. A class constructor can return a value. In Python, the constructor method is usually named __init__, and while it is not required to return a value, it is possible to include a return statement within the __init__ method if needed. C. A class constructor can be invoked directly from any of the subclasses. Subclasses can call the constructor of their superclass using the super() function. This allows the initialization code in the superclass to be executed. So, the correct choices are A and C.

Gvsl

A is incorrect. A class constructor can only return the value 'None'. If you try something else you will receive the errors below. Please check. TypeError: __init__() should return None, not 'int' TypeError: __init__() should return None, not 'float' TypeError: __init__() should return None, not 'str' TypeError: __init__() should return None, not 'list' TypeError: __init__() should return None, not 'tuple' TypeError: __init__() should return None, not 'dict

GvslOptions: CD

D is correct ---Script--- class c2: def __init__(self): c1.__init__(self) print('C2 init') class c1(c2): def __init__(self): print('C1 init') c2_var=c2() ---Output--- C1 init C2 init

aferiverOptions: CD

A class constructor cannot return a value and can be invoked directly from any subclass or superclass. Therefore, options B and A are incorrect. The correct answer is options C and D. Option C means that the class constructor can be invoked directly from any subclass. Option D means that the class constructor can be invoked directly from any superclass.

Senthorus

D is false. You can't call a constructor from any superclass