Classes & objects: Apex practice drills
Classes, constructors, methods, access modifiers, exceptions and enums.
Beginner · Free to run
- Build a Case summary class Beginner · 10 min
A class groups fields and methods, and new builds a separate object for each case.
- Build queue labels with parameters Beginner · 10 min
Parameters make one method reusable.
- Return a value and record work Beginner · 12 min
A method's return type promises a value back to the caller.
- Initialize a service appointment Beginner · 12 min
A constructor runs when new builds an object, so every new object starts with a valid state.
- Protect a support ticket subject Beginner · 12 min
private fields plus public methods let the class enforce its own rules.
- Expose a read-only quote total Intermediate · 15 min
Apex properties expose a value through get and set, and a getter-only property returns a derived value.
- Overload a Case label method Intermediate · 15 min
Overloading is one method name with different parameter lists; Apex picks the version whose parameters match your call.
- Route Cases with an enum Intermediate · 15 min
An enum is a type with a fixed set of named values.
- Recover from division by zero Intermediate · 15 min
try holds code that might fail; a matching catch runs instead if it does, and later code still runs.
- Reject an invalid discount Intermediate · 18 min
A custom exception gives a business rule its own type.
- Interface with two implementations Beginner · 14 min
An interface is a contract: method signatures with no bodies.
- virtual, override and super Intermediate · 18 min
A virtual method can be replaced by a subclass marked override, and super.method() runs the base version from inside the override.
- Constructor chaining with this(...) Intermediate · 14 min
A class can have several constructors.
- finally and several catch blocks Intermediate · 14 min
A try block can be followed by several catch blocks, one per exception type, and a finally block that runs no matter what.
- Static versus instance members Intermediate · 16 min
static members belong to the class and are shared across every instance for the whole transaction.
- Extend an abstract score rule Intermediate · 16 min
An abstract class can hold shared methods and leave one or more methods for a subclass to finish with override.