In a class, we have two types of numbers
If you would like to become a Salesforce Certified professional, then visit Mindmajix - A Global online training platform: " Salesforce Certification Training Course ". This course will help you to achieve excellence in this domain. |
Classname. Method name
Object name. method name;
↓
Object handle. method name;
Types of methods we perform all over Apex are
When to use static & non-static method as?
→ The non-static method is used w.r.t the object what you perform
→ The static method is used independently of the object what you perform
Memory Belongs To Static & Non-Static
Inheritance
Q: Why do we need inheritance?
It enables better and faster development of new features with the ability to reuse and modify the existing features
Ex:
Class account{ Name Number Balance | Class SavingAccount{ Name Number Balance Min bal | Class Current Account{ Name Number Balance Min bal Own bal |
Constructor Setter Getter showBal withdraw deposit } | Constructor Setter Getter showBal withdraw deposit } | Constructor Setter Getter showBal withdraw deposit } |
Syntax For Inheritance:
Class parent{
}
Class child extends parent{
}
Extends
(It is a keyword)
Nothing but visa
Class parent {
Private integer pm1: → security
Private integer pm2: → reusability
Protected integer pm3: → security + reusability
Scope: Within the class and related classes
Types of classes in an inheritance
1. Final
2. Virtual
3. Abstract
Every class is final by default in inheritance
Class type |
What we’re in a class
|
Objects creation
|
reversible
|
Final
|
Data members
member methods
def’s
|
We can create
objects
|
Not reversible
|
Virtual
|
Data members
member methods
def’s
|
We can create
objects
|
Reversible
|
Abstract
|
Data members
member methods
def’s and also
method prototypes
construct
|
No object can
be created
|
Reversible
|
Virtual → [Class, Method]
Override → method ↓
Years strike-off older one work with new only
→ Only virtual and abstract methods can be overridden
→ Abstract methods can only write in abstract classes
It is object-oriented programming that enables the child class to provide different implementations for a method that is already implemented in its parent class.
Q.Why overriding?
If a parent class method serves the purpose of a child class, do not override (or) else make the child over the ride
Abstract Class:
Class Type | method definition | Method prototype | Create objects | inherited |
Final | _/ | × | _/ | × |
Virtual | _/ | × | _/ | _/ |
abstract | _/ | _/ | × | _/ |
Class Type | method definition | Method prototype | override | Class type |
Final | _/ | × | × | Final |
Virtual | _/ | × | _/ | Virtual and abstract |
abstract | × | _/ | _/ | abstract |
Key Words:
Q.When to make a method final?
Q.When to make a method virtual?
Q.When to make a method abstract?
Ex:
Public virtual class parent {
Private integer pvt_mem;
Protected integer ptd_mem;
Public integer pub_mem;
Public virtual void gets values (){
System. Debug (‘Pvt Mem’ +pvt_mem);
System.debug(‘ptd Mem’ +ptd_mem);
System. Debug (‘pub mem’+ pub_mem);
}
}
Public class child extends parent {
Private integer pvt_ch_mem
Public override void get values () {
System. Debug (‘Pvt ch Mem’ + pvt_ch_mem);
}
}
Global class test {
Public static test method void main () {
Parent p1= new parent ();
P2.get values ();
Child c1= new child(); c1.gets values ();
}
Ex:
Public abstract class parent {
Public abstract void gets values ();
}
Public class child extends parent {
Private’s integer pvt_ch_mem;
Public override void get values () {
System. Debug c’ Pvt.Mem’ + pvt_ch_mem);
}
}
Public class test {
Public static test method void main () {
Child c1 =new child ();
C1.gets values ();
}
}
Parent p1 = new child ();
Parent handle can refer to the child object
Child c1 = new parent ();
Parent object doesn’t handle the child
→ Child handles can’t refer to the parent object
Explore Salesforce Sample Resumes! Download & Edit, Get Noticed by Top Employers! |
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Salesforce Training | Nov 19 to Dec 04 | View Details |
Salesforce Training | Nov 23 to Dec 08 | View Details |
Salesforce Training | Nov 26 to Dec 11 | View Details |
Salesforce Training | Nov 30 to Dec 15 | View Details |
Arogyalokesh is a Technical Content Writer and manages content creation on various IT platforms at Mindmajix. He is dedicated to creating useful and engaging content on Salesforce, Blockchain, Docker, SQL Server, Tangle, Jira, and few other technologies. Get in touch with him on LinkedIn and Twitter.