A class extends another class using the extends keyword in the class definition. A class can only extend one other class, but it can implement more than
In the previous blog, we learned “Polymorphic Query in Salesforce” If you have missed the session, please refer to the below link.
Inheritance is a fundamental concept in any programming language where the child class can access the properties or methods of the parent class that it’s extending.
If you have a requirement where you want to inherit one class in another class then you need to make that class either virtual or abstract.
You can extend a class to provide more specialized behavior. Below is the example virtual class with virtual methods.
A class extends another class using the extends keyword in the class definition. A class can only extend one other class, but it can implement more than one interface.
A person at the same time can have different characteristics. Like a man, at the same time is a father, a husband, and a team member. So the same person possesses different behavior in different situations. This is called polymorphism.
What is Method Overloading in Salesforce
If a class has multiple methods having the same name but different parameters, it is known as Method Overloading.
There are two ways to overload the method in Java
Create a virtual Class named Vehicle and create the below methods
Create another class Mercedes that extends the Vehicle class and overrides the above methods within the Mercedes class.