You need to sign in to do that
Don't have an account?

Which code block will run successfully in an execute anonymous window
A developer has the controller class below
Public with sharing class myFooController {
public integer prop {get; private set;}
}
Which code block will run successfully in an execute anonymous window?
a. myFooController m = new myFooController();
System.assert(m.prop != null);
b. myFooController m = new myFooController();
System.assert(m.prop == 1);
c. myFooController m = new myFooController();
System.assert(m.prop == null);
d. myFooController m = new myFooController();
System.assert(m.prop == 0);
Can someone please help me solve this question? I found out that the correct answer is option (C) but I don't understand the reason behind it.
Public with sharing class myFooController {
public integer prop {get; private set;}
}
Which code block will run successfully in an execute anonymous window?
a. myFooController m = new myFooController();
System.assert(m.prop != null);
b. myFooController m = new myFooController();
System.assert(m.prop == 1);
c. myFooController m = new myFooController();
System.assert(m.prop == null);
d. myFooController m = new myFooController();
System.assert(m.prop == 0);
Can someone please help me solve this question? I found out that the correct answer is option (C) but I don't understand the reason behind it.
The reason is simply because the prop variable is never defined in the constructor of the controller and hence its value is null. Therefore, executing below code:
myFooController m = new myFooController();
System.assert(m.prop == null);
in the anonymous window will always evaluate to true and thus it will execute.
All Answers
Best Regards: Students Help (https://www.essaycorp.co.uk/nursing-essay-help/)
From my understanding ,
In the above controller, option b from amongst the answers would be correct.the Get method will pass data from the controller to the page. Since the Get does not return anything, it will simply return a variable of type Integer but with no value set, hence it will be null
now, lets got out on a limb with my understanding of getters/setters
if we did
myFooController m = new myFooController();
System.assert(m.prop == 1);
HTH
Andrew
The reason is simply because the prop variable is never defined in the constructor of the controller and hence its value is null. Therefore, executing below code:
myFooController m = new myFooController();
System.assert(m.prop == null);
in the anonymous window will always evaluate to true and thus it will execute.