Object-Oriented Principles in Apex Flashcards

1
Q

What are Constructors?

A
  • constructors are methods that are called when the class instantiated, they’re used to define the initial state of the object by performing operations such as setting values for class variables
  • every Apex class has a default constructor that doesn’t take any arguments
    • if we write our own constructor, this default no-argument constructor will go away
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is Encapsulation?

A
  • encapsulation is about bundling data and methods that work with that data into one unit (i.e. a class or object), giving, yet still controlling, access to the unit’s contents
  • the static keyword is used to indicate that a member variable or method is associated with the class itself, rather than an instance of that class
  • anything that’s not declared with the static keyword will be an instance method or variable, meaning that we’ll need to instantiate the enclosing class before we’ll be able to work with it
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the different types of Access Modifiers?

A
  • private
    • the class/variable/method can’t be referenced outside of the class that declares it
  • protected
    • the method/variable can be referenced by anything within the class that declares it, as well as by anything within any inner classes or subclasses
  • public
    • the class/variable/method can be referenced from anywhere within the same namespace
  • global
    • the class/variable/method can be referenced by any code, regardless of namespace
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What are properties?

A
  • properties are variables that include a getter and setter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What are the different types of properties?

A
  • read-only properties
    • those with only a getter that’s accessible to outside entities
  • write-only properties
    • those with only a setter that’s accessible to outside entities
  • read-write properties
    • those with accessible getters and setters
  • automatic property
    • a read-write property that uses the default getter and setter
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What is Abstraction?

A
  • abstraction bundle together repetitive logic so that it can be invoked repetitively, rather than being written repetitively
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is an Abstract Class?

A
  • an abstract class is a class that’s declared with the abstract keyword and generally contains at least one abstract method
  • an abstract method only has a signature, it doesn’t a body
  • we can’t instantiate an abstract class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a Virtual Class?

A
  • virtual classes are declared with the virtual keyword and can contain virtual and final methods (i.e. no abstract methods)
  • virtual methods are declared with the virtual keyword and have a full definition
  • virtual classes (unlike abstract classes) can be instantiated
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is an interface?

A
  • an interface is an Apex file that consists solely of method signatures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Inheritance?

A
  • inheritance allows one entity (i.e. class or object) to take on the state and/or behavior of an existing entity while still having its own separate characteristics
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How do we extend a class?

A
  • when we inherit from a class, we use the extends keyword
  • to be able to extend a class, that class needs to be either abstract or virtual (final classes cannot be extended)
public class TyrannosaurusRex extends GreenDinosuar {
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How do we implement a interface?

A
  • we can implement interfaces by using the implements keyword
  • any class that implements an interface must fully define all methods that it inherits from that interface
public class ImplementingClass implements InterfaceOne, InterfaceTwo {
}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the “super” keyword?

A
  • the super keyword allows us to call a method/variable from a parent class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is the “this” keyword?

A
  • the this keyword refers to instance variables or methods in the current class
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What is Polymorphism?

A
  • polymorphism is the act of defining constructs (i.e. methods) of different types that have the same name
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is Method Overloading?

A
  • method overloading is the act writing multiple methods in the same class that each have the same name, but different signatures
  • to overload an Apex method, the overloaded method will need to have a different number of parameters or different types of parameters
17
Q

What is Constructor Overloading?

A
  • constructor chaining
  • constructor overloading is a subset of method overloading where we call a second constructor from another constructor
  • to invoke a second constructor from another, we’ll use this()
  • we can also invoke a parent constructor with the use super()
18
Q

What is Method Overriding?

A
  • method overriding pertains to methods in subclasses that have the same signature as a method in a parent class
  • we create overridden methods by using the override keyword after the access modifier in our method signature
19
Q

What is an Inner Class?

A
  • inner classes are classes that are declared within another
  • we can’t continually nest inner classes - i.e. an inner class can’t contain another inner class