PCAP Exam QuestionsBrowse all questions from this exam

PCAP Exam - Question 69


A class constructor (Choose two.)

Show Answer
Correct Answer: BC

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

5 comments
Sign in to comment
SenthorusOptions: BC
Jul 5, 2023

I think it's true

Mikku123Options: BD
Aug 15, 2023

B & D.

aferiverOptions: CD
Mar 26, 2023

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
Jul 5, 2023

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

GvslOptions: CD
Oct 30, 2023

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

kstrOptions: AC
Nov 21, 2023

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
Nov 29, 2023

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