Apex OOP Interview Questions test how well you design Apex with classes, interfaces and inheritance, not just write single methods. Interviewers ask about constructors, access modifiers, static members, abstract and virtual classes, and how these ideas show up in triggers and async jobs. Good answers show you can build code that a team can extend safely.
Last reviewed for the Winter ’27 release (November 2026).
This is Part 4 of our Salesforce developer interview series. It collects the object-oriented questions asked most, from basic to advanced, with short answers and code. It builds on Apex classes, objects and constructors, Apex access modifiers and static vs instance Apex.
What are Apex OOP Interview Questions?
Apex OOP Interview Questions focus on object-oriented programming in Apex: classes, objects, encapsulation, inheritance, polymorphism and abstraction. They also cover Apex-specific rules, such as classes being final by default. So they test design thinking as well as syntax.
Think of a car factory. The blueprint is the class, each car is an object, and options like a sunroof are added by extending the base design. OOP helps you build many cars from one design without rewriting it.
Why Apex OOP Interview Questions Matter
Real projects depend on clean class design. Here is why Apex OOP Interview Questions matter.
- First, trigger handlers, services and selectors are all classes.
- Also, async Apex uses interfaces like Queueable and Database.Batchable.
- Next, tests rely on interfaces for mocking.
- Apex rules differ from Java in key places, such as default finality.
- Finally, senior roles judge you on design, not syntax.
So OOP knowledge separates junior answers from senior ones.
How to Prepare for Apex OOP Interview Questions
Preparing for Apex OOP Interview Questions follows five steps. First, learn the four OOP pillars with one Apex example each. Next, memorise the access modifiers and default values. Then write a small hierarchy with an abstract class, a virtual method and an interface. After that, practise system interfaces, such as Queueable and Comparable. Finally, explain one real design from your project in two minutes.

Apex Access Modifiers at a Glance
The table below shows who can use members with each modifier.
| Modifier | Visible to | Typical use |
|---|---|---|
| private | Same class only, the default for members | Helper methods |
| protected | Same class and subclasses | Shared logic in a base class |
| public | Code in the same namespace | Most application code |
| global | Any namespace | Managed packages and web services |
Abstract Class vs Interface
The table below compares two of the most asked-about OOP tools.
| Feature | Abstract class | Interface |
|---|---|---|
| Method bodies | Some allowed | None |
| Instance variables | Allowed | Not allowed |
| How many per class | Extend only one | Implement many |
| Constructor | Allowed | Not allowed |
| Best for | Shared base behaviour | A contract many classes follow |
When to use which is a favourite question. Use an interface for a contract, and an abstract class when subclasses also share code.

Basic Apex OOP Interview Questions
These Apex OOP Interview Questions are the definitions every developer should know.
Questions on Classes and Objects
Q1: What is a class?
A class is a blueprint that defines variables and methods. Then you create objects from it.
Follow-up you may get: Can a class have no methods? Yes, for example a simple class that only holds data.
Q2: What is an object?
An object is an instance of a class, created with new. For example, CourseService svc = new CourseService();.
Interview tip: always give an example with new. It shows you know the difference from a class.
Q3: What are the four pillars of OOP?
Encapsulation, inheritance, polymorphism and abstraction. Apex supports all four.
In short: encapsulation hides data behind methods, inheritance reuses a parent’s code, polymorphism lets one variable hold different types, and abstraction shows what a class does without how. The next questions explain each with an Apex example.
Q4: What is encapsulation?
It hides data inside a class and exposes it through methods or properties. So other code cannot change it carelessly.
Q5: What is inheritance?
A class reuses another class’s code with extends. However, Apex allows only single inheritance.
Q6: What is polymorphism?
One reference can point to different subclasses and call their own versions of a method. For example, a DiscountStrategy variable can hold any strategy.
Interview tip: use a Salesforce example, like a List of Database.Batchable. It sounds less like a textbook.
Q7: What is abstraction?
It shows only what an object does, not how. So interfaces and abstract classes provide abstraction.
Q8: What is the difference between a class and an interface?
A class has code that runs and can create objects. An interface only lists method signatures that classes promise to write. A class can extend one class but implement many interfaces.
Q9: What is an inner class?
It is a class declared inside another class. Also, Apex allows only one level of inner classes.
Questions on Constructors
Q10: What is a constructor?
It is a special method with the class name that runs when an object is created. So it sets starting values.
Follow-up you may get: Can a constructor return a value? No, it has no return type.
Q11: What happens if you do not write a constructor?
Apex gives a default no-argument constructor. However, it disappears once you write any constructor.
Interview tip: the trap is that the default constructor disappears once you write one. Say it clearly.
Q12: Can you overload constructors?
Yes, so a class can have several constructors with different parameters. Each must have a unique signature.
Q13: How does one constructor call another?
Call this(…) as the first statement of the constructor.
That lets several constructors share one setup method, so you do not repeat code.
Example: public Course(String name) { this(name, 30); } calls the two parameter constructor with a default of 30 seats.
Q14: How does a subclass call its parent constructor?
Call super(…) as the first statement in the subclass constructor.
If you do not, Apex calls the parent’s no argument constructor for you, and fails to compile if the parent has none.
Example: public OnlineCourse(String name) { super(name); this.platform = ‘Zoom’; }
Q15: Can a constructor throw an exception?
Yes. If the input is invalid, throwing an exception stops the object from being created in a bad state.
Example: if (seats < 0) throw new IllegalArgumentException(‘Seats cannot be negative’);
Q16: Can a constructor be private?
Yes, for example in a Singleton. Then other code must use a static method to get the instance.
Follow-up you may get: Can an abstract class have a constructor? Yes, and subclasses call it with super().
Questions on Access Modifiers
Q17: What is the default access modifier for class members?
private. Methods and variables are hidden from other classes unless you say otherwise.
That is a safe default, because nothing leaks by accident. Add public, protected or global only when another class really needs access.
Q18: Which modifier must a top-level class use?
A top level class must be public or global. Test classes can also be private.
Here is how the four access modifiers compare:
| Modifier | Who can use it | Typical use |
|---|---|---|
| private | Only the same class | Helpers and internal fields |
| protected | The class, inner classes and subclasses | Hooks for child classes |
| public | Any code in the same namespace | Most classes and methods |
| global | Any code, even other namespaces | Managed packages, web services |
Q19: What does protected mean in Apex?
The member is visible to the class, its inner classes and its subclasses. So base classes share helpers with children.
Q20: When do you need global?
When code in another namespace must use the class, such as managed packages or webservice methods. Otherwise, use public.
Interview tip: say you avoid global unless you build packages, because it cannot be undone easily in a released managed package.
Q21: What is the difference between public and global?
public lets any code in the same namespace use the class or member. global opens it to every namespace, which managed packages and web services need. In a released managed package, global signatures cannot be removed later, so use global only when you must.
Q22: What does @TestVisible do?
It lets test classes see private members. So you test logic without making it public.
Example: mark a private helper @TestVisible private static Decimal calcTax() so the test class can call it directly, while production code still cannot.
Intermediate Apex OOP Interview Questions
These Apex OOP Interview Questions cover static members, properties and inheritance rules.
Questions on Static and Instance
Q23: What is a static variable?
A static variable belongs to the class, not to an object, and lives for one transaction.
Every piece of code in the same transaction sees the same value, which is why it suits counters and recursion flags. When the transaction ends, it resets.
Q24: What is a static method?
It is called on the class, such as CourseService.reprice(ids). So you do not need an object.
Follow-up you may get: Can you call a static method on an object? No, Apex requires the class name.
Q25: Can a static method use instance variables?
No, because a static method has no object to read instance variables from.
Pass the values in as parameters, or create an object inside the method. Example: public static Decimal total(List<Course__c> courses) works on what it is given.
Q26: Are static variables shared between users?
No. Static variables reset after each transaction, so they are not shared between users or requests.
For values that must last longer, use Platform Cache, custom settings or custom metadata.
Interview tip: many candidates think static means shared across users. Correcting that wins points.
Q27: What is a static initialisation block?
It is code inside static { } that runs once when the class is first used. For example, it can load a map of settings.
Q28: When should a method be static and when instance?
Make it static when it needs no object state, like a utility that formats phone numbers. Make it instance when it works with an object’s own data, like a Course object calculating its own fee. Instance methods are also easier to replace with fakes in tests.
Q29: Why are static variables used for trigger recursion?
Because they keep their value during the transaction. So a flag or a set of processed Ids stops repeat runs.
Questions on Properties
Q30: What is a property in Apex?
It is a variable with get and set accessors, such as public Integer seats { get; set; }. So you can add logic on read or write.
Follow-up you may get: Do properties work in LWC? Yes, @AuraEnabled properties on Apex classes are sent to components.
Q31: How do you make a read-only property?
Give it a public get and a private set, like public Integer seats { get; private set; }.
Outside code can read seats, but only the class itself can change it, which protects the value from careless updates.
Q32: What is an automatic property?
A property with empty get; and set; accessors, so Apex stores the value for you.
Example: public String trainerName { get; set; } works like a public variable today, but you can add logic to get or set later without changing the code that uses it.
Q33: What is the difference between a property and a public variable?
Both can be read and set from outside. A property lets you add logic in get or set later, like validation or a calculated value, without changing the code that uses it. That makes properties safer for public classes.
Q34: Can a property have logic?
Yes, for example a get that calculates a value. However, keep it light, because it may run often.
Questions on Inheritance Rules
Q35: Can you extend any Apex class?
No. Apex classes are final by default, so a parent must be marked virtual or abstract before anyone can extend it.
This is different from Java, where classes can be extended unless marked final.
Interview tip: compare with Java here. It shows you know why the error happens.
Q36: What is a virtual class?
A virtual class can be extended and can also be created on its own. Its virtual methods can be overridden.
| Class type | Can create objects | Can be extended | Methods without bodies |
|---|---|---|---|
| Default (no keyword) | Yes | No | No |
| virtual | Yes | Yes | No |
| abstract | No | Yes | Yes, abstract methods |
Example: a virtual BaseHandler gives empty beforeInsert() methods that each object’s handler can override.
Q37: What is an abstract class?
It cannot be instantiated and may have abstract methods without bodies. So subclasses must implement them.
Follow-up you may get: Can an abstract class have normal methods? Yes, with full bodies.
Q38: What keyword is needed to override a method?
Use override in the child, and the parent method must be virtual or abstract. Otherwise, the compiler rejects it.
Q39: How do you call the parent version of a method?
Call super.methodName() inside the overriding method.
That way the child adds to the parent’s behaviour instead of replacing it.
Example: public override void validate() { super.validate(); if (seats > 50) throw new SeatLimitException(‘Too many seats’); }
Q40: Can a class extend more than one class?
No. Apex supports single inheritance only, so a class can extend one class.
It can implement many interfaces, though, which is how you combine several contracts, like Queueable and Database.AllowsCallouts.
Q41: What is method overloading?
Several methods share a name but have different parameters. So callers pick the version they need.
Q42: What is the difference between an abstract method and a virtual method?
An abstract method has no body, so every subclass must write it. A virtual method has a body, and subclasses may override it if they want. Abstract methods can only live in abstract classes.
Q43: What is the difference between overloading and overriding?
Overloading is same name, different parameters, in one class. Overriding replaces a parent method in a child class.
Interview tip: give one line examples of each. Definitions alone sound memorised.
Questions on Interfaces
Q44: What is an interface?
It is a contract of method signatures with no bodies. So any implementing class must provide those methods.
Follow-up you may get: Can an interface have static methods? No.
Q45: Can an interface extend another interface?
Yes, with extends. Classes that implement the child interface must provide the methods of both.
Example: public interface PremiumDiscount extends Discount { Decimal bonus(); } means a class must write apply() and bonus().
Q46: What modifier must interface methods use in the class?
They must be public or global in the implementing class.
An interface defines a public contract, so the class cannot hide those methods with private or protected. The compiler gives an error if you try.
Q47: Name some system interfaces in Apex.
Queueable, Schedulable, Database.Batchable, Comparable, Comparator and HttpCalloutMock. Each powers a platform feature.
Q48: What is a marker interface?
It has no methods but flags a class, such as Database.Stateful or Database.AllowsCallouts. So the platform changes behaviour.
Interview tip: name Database.Stateful and Database.AllowsCallouts. They are the examples interviewers expect.
Q49: Can one class implement two interfaces that have the same method?
Yes. If both interfaces declare the same method signature, the class writes it once and satisfies both.
Q50: How do you check an object’s type?
Use instanceof, such as if (s instanceof StudentDiscount). Then cast safely.
In switch statements, when Account a or when StudentDiscount d checks the type and casts in one step.
Advanced Apex OOP Interview Questions
These Apex OOP Interview Questions appear in senior and lead interviews.
Questions on Design
Q51: How do interfaces help testing?
You can pass a fake implementation into the class under test. So tests control results without real data or callouts.
Q52: What is dependency injection in Apex?
It means passing dependencies in, often through the constructor, instead of creating them inside. As a result, classes are easier to test and swap.
Interview tip: tie it to tests. Dependency injection is mainly about swapping real services for fakes.
Q53: How do you create a class from its name at runtime?
Use Type.forName(‘ClassName’).newInstance(), then cast to an interface. So custom metadata can choose the class.
Follow-up you may get: What if the class name is wrong? Type.forName returns null, so check before newInstance().
Q54: Why are Apex classes final by default?
Because it protects classes from unplanned extension. So you opt in with virtual or abstract.
Q55: What is composition, and why is it often preferred over inheritance?
Composition means a class holds other objects and uses them, instead of extending a parent. It keeps classes small and lets you swap parts, like giving an OrderService a TaxCalculator. Inheritance ties a child tightly to its parent, so changes ripple down.
Q56: Can an abstract class implement an interface?
Yes, and it may leave some methods for subclasses to implement.
This is common in frameworks: an abstract base handler implements the interface and gives default behaviour, and each subclass fills in the rest.
Questions on Equality and Singletons
These Apex OOP Interview Questions often trip up Java developers.
Q57: How do you make a custom class work as a Map key or in a Set?
Override equals() and hashCode() in your class.
Without them, Apex compares references, so two objects with the same values still count as different, and Map lookups fail.
Example: equals() compares courseCode, and hashCode() returns courseCode.hashCode().
Q58: What is the Singleton pattern?
It ensures one instance per transaction using a private constructor and a static getInstance method. It suits shared settings.
Interview tip: mention that a Singleton lives only for one transaction in Apex.
Q59: Do inner classes see the outer class’s instance variables?
No. Inner classes behave like static nested classes, so they cannot see the outer object’s instance variables.
Pass the data into the inner class through its constructor or method parameters.
Q60: What naming rule applies to custom exception classes?
Their names must end with Exception, and they extend Exception. For example, SeatLimitException.
Q61: What is the difference between with sharing classes and OOP access modifiers?
Access modifiers control which code can call members, while sharing keywords control which records the code can see. They solve different problems.
Q62: What does the virtual keyword on a method allow?
It lets subclasses override that method. Without virtual or abstract, the method cannot be overridden.
Mark only the methods meant to change as virtual, so the rest of the class keeps its behaviour.
Q63: What does the this keyword mean?
It refers to the current object. Use it to tell a field apart from a parameter with the same name, like this.name = name, or to call another constructor with this(…).
Q64: Can you override a static method?
No, static methods belong to the class and are not inherited for overriding.
Call a static method on the class that defines it, like BaseHandler.log(), and design shared static helpers so they do not need to change per subclass.
Questions on Real Patterns
Q65: How does Queueable use OOP?
Your class implements the Queueable interface and its execute method. Then the platform calls it polymorphically.
Q66: How does a trigger handler use inheritance?
A virtual base handler defines beforeInsert, afterUpdate and so on. Then each object’s handler overrides only what it needs.
Follow-up you may get: Does the trigger still need one line per event? No, it calls the handler once, and the handler checks the context.
Q67: How do you share common code across services?
Put it in an abstract base class or a utility class with static methods. Choose based on whether state is needed.
Q68: What is a wrapper class?
A class that combines records or values with extra fields, such as a selected flag for an LWC table.
Q69: How do OOP ideas show up in Batch Apex?
Your batch class implements the Database.Batchable interface, so Salesforce can call start, execute and finish without knowing your class. Adding Database.Stateful or Database.AllowsCallouts uses marker interfaces to change how it runs.
Q70: Why avoid very large classes?
Because they mix concerns, become hard to test and hit the class size limit. So split by responsibility.
Scenario-Based Apex OOP Interview Questions
These Apex OOP Interview Questions ask you to design or fix classes.
Questions on Design Tasks
Q71: Design discounts for students and corporate clients.
Create a DiscountStrategy interface with apply(), then one class per discount. Finally, a factory picks the class by customer type.
Interview tip: name the pattern: strategy plus a factory. Naming patterns shows design maturity.
Q72: Your class cannot be extended. Why?
Because the parent class is not marked virtual or abstract.
Apex classes are final by default, so add virtual or abstract to the parent class. Each method you want to change must also be virtual or abstract.
Q73: A test needs a fake callout service. How do you design it?
Define an interface for the service and inject it. Then pass a fake in tests and the real one in production.
Follow-up you may get: Can the Stub API create the fake for you? Yes, Test.createStub builds one at run time.
Q74: Why does “override” fail to compile?
Either the parent method is not virtual or abstract, or the signature is different.
Check both: the parent needs virtual or abstract, and the child’s method must have the same name, parameters and return type.
Q75: How do you stop other code from creating objects of a class?
Make the constructor private and offer a static factory method.
Example: private CourseService() {} and public static CourseService getInstance() { … } This is how the Singleton pattern controls creation.
Q76: Several classes share validation but differ in saving. What design fits?
Use an abstract class with a shared validate() and an abstract save() that each subclass writes.
This is the template method pattern: the base class runs validate() then save(), and each subclass fills in only the part that differs.
Q77: How do you expose a value but stop outside changes?
Use a property with a public get and a private set.
Example: public Decimal totalFee { get; private set; } The class sets it after calculating, and other code can only read it.
Q78: Code uses a Set of custom objects but duplicates appear. Why?
Because equals() and hashCode() are not overridden, so references are compared. Override both.
Interview tip: give the fix and the reason together: override both methods, because Sets use hashCode first.
Q79: How would you explain polymorphism with a real Salesforce example?
Say that List<Database.Batchable<sObject>> could hold different batch classes, and the platform calls each one’s execute. So one call works for many types.
Q80: Design a notification service that can send email, SMS or WhatsApp.
Create a NotificationChannel interface with send(String to, String message), and one class per channel. A small factory picks the channel from custom metadata, so adding a new channel means one new class and one metadata record, with no change to existing code.
Q81: Interface or abstract class for payment providers?
Use an interface, PaymentProvider, so each provider implements charge() its own way. Add an abstract base only if they share code.
A Real Apex OOP Interview Questions Answer
A common live task is “show inheritance and polymorphism in Apex”. Here is a short answer.
public abstract class CourseFee {
protected Decimal baseFee;
public CourseFee(Decimal baseFee) { this.baseFee = baseFee; }
public abstract Decimal finalFee();
public virtual String label() { return 'Standard'; }
}
public class OnlineFee extends CourseFee {
public OnlineFee(Decimal f) { super(f); }
public override Decimal finalFee() { return baseFee * 0.85; }
public override String label() { return 'Online'; }
}
public class ClassroomFee extends CourseFee {
public ClassroomFee(Decimal f) { super(f); }
public override Decimal finalFee() { return baseFee + 500; }
}
// Anonymous Apex
List<CourseFee> fees = new List<CourseFee>{ new OnlineFee(5000), new ClassroomFee(5000) };
for (CourseFee f : fees) {
System.debug(f.label() + ': ' + f.finalFee());
}
Explain that the abstract class shares the constructor and forces finalFee(). Then each subclass gives its own rule, and one loop calls them through the parent type.
Here is the output.
Online: 4250.00
Standard: 5500
Common Mistakes with Apex OOP Interview Questions
- Saying all classes can be extended like in Java.
- Forgetting the override keyword.
- Believing static variables are shared across users.
- Mixing up access modifiers with sharing keywords.
- Using a Set of custom objects without equals and hashCode.
Best Practices for Answering Apex OOP Interview Questions
- Give an Apex example, not a generic textbook one.
- Mention Apex-specific rules, such as final by default.
- Link interfaces to testing and dependency injection.
- Show a small class hierarchy on a whiteboard if asked.
- Keep classes focused on one responsibility in your examples.
Official Resources
Quick Recap
- Apex OOP Interview Questions test classes, constructors and modifiers.
- Members are private by default, and classes are final by default.
- Use virtual, abstract and override for inheritance.
- Interfaces define contracts and help testing.
- Static variables last one transaction only.
What’s Next?
Next in the series, practise String, Date and Math methods with our Apex methods interview questions.


