nerdexam
Salesforce

PDI · Question #239

A developer wrote the following two classes: The StatusFetcher class successfully compiled and saved. However, the Calculator class has a compile time error. How should the developer fix this code?

The correct answer is B. Make the isActive method in the StatusFetcher class public. To fix the compile-time error in the Calculator class attempting to call a method from StatusFetcher, the isActive method in StatusFetcher must be declared as public to allow external access.

Submitted by skyler.x· Apr 18, 2026Logic and Process Automation

Question

A developer wrote the following two classes:

The StatusFetcher class successfully compiled and saved. However, the Calculator class has a compile time error. How should the developer fix this code?

Exhibit

PDI question #239 exhibit

Options

  • AChange the class declaration for the statusFetcher class to public with inherited sharing.
  • BMake the isActive method in the StatusFetcher class public.
  • CMake the doCalculations method in the Calculation class private.
  • DChange the class declaration for the Calculator class to public with inherited sharing.

How the community answered

(36 responses)
  • B
    92% (33)
  • C
    3% (1)
  • D
    6% (2)

Why each option

To fix the compile-time error in the Calculator class attempting to call a method from StatusFetcher, the `isActive` method in StatusFetcher must be declared as public to allow external access.

AChange the class declaration for the statusFetcher class to public with inherited sharing.

Changing the class declaration to `public with inherited sharing` controls record sharing context, which is unrelated to the compile-time error caused by insufficient method visibility between classes.

BMake the isActive method in the StatusFetcher class public.Correct

For the Calculator class to invoke the `isActive()` method of the StatusFetcher class, the `isActive()` method must be declared with the `public` access modifier, allowing it to be visible and callable from other classes. By default, methods without an explicit access modifier are private.

CMake the doCalculations method in the Calculation class private.

Making the `doCalculations` method private would restrict access to `doCalculations` itself but would not resolve the compile-time error occurring within `doCalculations` when attempting to call an inaccessible method from StatusFetcher.

DChange the class declaration for the Calculator class to public with inherited sharing.

Changing the Calculator class declaration to `public with inherited sharing` controls record sharing, which does not address the method accessibility issue between the two classes.

Concept tested: Apex class and method access modifiers

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

Topics

#Apex#Access Modifiers#Method Visibility#OOP Concepts

Community Discussion

No community discussion yet for this question.

Full PDI Practice