Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam PCAP All Questions

View all questions & answers for the PCAP exam

Exam PCAP topic 1 question 69 discussion

Actual exam question from Python Institute's PCAP
Question #: 69
Topic #: 1
[All PCAP Questions]

A class constructor (Choose two.)

  • A. can return a value
  • B. cannot be invoked directly from inside the class
  • C. can be invoked directly from any of the subclasses
  • D. can be invoked directly from any of the superclasses
Show Suggested Answer Hide Answer
Suggested Answer: BC 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
kstr
1 year ago
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.
upvoted 1 times
Gvsl
12 months ago
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
upvoted 2 times
...
...
Gvsl
1 year, 1 month ago
Selected Answer: 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
upvoted 1 times
...
Mikku123
1 year, 3 months ago
B & D.
upvoted 2 times
...
Senthorus
1 year, 4 months ago
Selected Answer: BC
I think it's true
upvoted 3 times
...
aferiver
1 year, 8 months ago
Selected Answer: 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.
upvoted 1 times
Senthorus
1 year, 4 months ago
D is false. You can't call a constructor from any superclass
upvoted 4 times
...
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...