CRT-450 Exam QuestionsBrowse all questions from this exam

CRT-450 Exam - Question 23


A developer has the controller class below.

Which code block will run successfully in an execute anonymous window?

Show Answer
Correct Answer: C

The code block will run successfully because in Apex, when an object is instantiated, any uninitialized instance variables default to null. Since the 'prop' property is of type Integer and is not explicitly assigned a value in the constructor or elsewhere in the class, its default value will be null. Therefore, the assertion 'System.assert(m.prop == null)' will evaluate to true.

Discussion

4 comments
Sign in to comment
kimmaayyaaOption: C
Jul 27, 2022

c is correct answer The reason is that the value of prop variable is never defined in the constructor of controller hence it is null

1vanTT
Apr 25, 2023

https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/langCon_apex_variables.htm

TDB97Option: C
Jun 10, 2024

All the code will run successfully, but not all of them will return true.. But yes C would be correct if we solve for true

Ankit_SwamiOption: C
Jun 20, 2024

If you declare a variable and don't initialize it with a value, it will be null. In essence, null means the absence of a value.