A developer has the following class and trigger code.

Which code segment should a developer insert at the XXX to set the baseCost variable to the value of the class variable smokerCharge?
A developer has the following class and trigger code.
Which code segment should a developer insert at the XXX to set the baseCost variable to the value of the class variable smokerCharge?
In object-oriented programming, a static variable belongs to the class itself rather than any instance of the class. Thus, it is accessed using the class name rather than an instance of the class. In this case, the variable 'smokerCharge' is declared as static within the 'InsuranceRates' class. Therefore, the correct way to access it is by using 'InsuranceRates.smokerCharge'. This ensures that the variable is accessed directly from the class, not from an instance of the class.
A is correct. https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_static.htm A class static variable can’t be accessed through an instance of that class. If class MyClass has a static variable myStaticVariable, and myClassInstance is an instance of MyClass, myClassInstance.myStaticVariable isn’t a legal expression.
the answer is D not A. You are instantiating a reference to the class InsuranceRates as 'rates', which has a static variable named smokerCharge which is accessible outside of that class. As such, it would be rates.smokerCharge
the variable is static and is only accessible as shown in the answer A no instance needed
Just tried the code in dev console. A is the correct answer.
A is correct. verified it in the dev console. Option D won't even save, you will get the error "Static field cannot be referenced from a non static context: smokerCharge from the type InsuranceRates"
correct answer is D, b/c the InsuranceRates is instatiated by rates.
Wrong, static variable are not accessed via instance. It's only via the class. Basic OOP.
Spot on.
a.BECAUSE SMOKERcHARGE IS A STATIC VARIABLE
A is correct.
A - Correct A class static variable can’t be accessed through an instance of that class. If class MyClass has a static variable myStaticVariable, and myClassInstance is an instance of MyClass, myClassInstance.myStaticVariable isn’t a legal expression.