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

Exam CRT-450 All Questions

View all questions & answers for the CRT-450 exam

Exam CRT-450 topic 1 question 109 discussion

Actual exam question from Salesforce's CRT-450
Question #: 109
Topic #: 1
[All CRT-450 Questions]

A developer creates a custom controller and custom Visualforce page by using the code block below.

What can the user expect to see when accessing the custom page?

  • A. a, b, b
  • B. a, b, getMyString
  • C. a, a, a
  • D. b, a, getMyString
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
irina_735
1 year, 1 month ago
Selected Answer: C
C is correct I`v tested it. The order of execution: {!StringMethod} invokes getStringMethod() that calls myString getter in which we have assignment myString = a, and than getter returns first 'a'. Both next {!myString} invokes myString variable getter, so we have 'a' and 'a' again. And getMyString() metod is never called.
upvoted 2 times
...
govosen887
1 year, 7 months ago
Selected Answer: C
The question seems to be wrong since there is no getStringMethod defined - but assuming that it's what "StringMethod" was supposed to reference - the answer is a, a, a Even though getStringMethod is called before the getter, the method then attempts to retrieve the value to check if it's null. This retrieval calls the getter - and causes the value to be set to 'a' before being returned. Basically, the property is null only as long as you don't check what it is - the first attempt to check its value changes its state.
upvoted 2 times
...
Gusfn
2 years, 1 month ago
Selected Answer: C
myString is an APEX property. The get accessor executes when the property is read. Hence, the answer is a,a,a
upvoted 3 times
...
lmeloni91
2 years, 5 months ago
I tested the full code in Dev console and the answer is: a, a, a I've struggled to understand the reason, but it seems that getStringMethod uses the getter to access myString, so it receives the value 'a' and doesn't enter the If statement at all
upvoted 4 times
...
noox
2 years, 10 months ago
Selected Answer: C
Just test this code in dev console : String myString { get { if (myString == null) { myString = 'a'; } return myString; } private set; } system.debug(myString == null); You get a 'false' printed. Because as soon as you try to evaluate if myString == null in the debug, you enter in the getter of myString, who evaluate myString to null, and set it to 'a'. So myString is no longer null and the system.debug(myString == null) = false :)
upvoted 2 times
...
OMsairam
2 years, 11 months ago
it should be b,a,a
upvoted 2 times
noox
2 years, 11 months ago
Nope, A,A,A is the corect answer
upvoted 6 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 ...