You need to sign in to do that
Don't have an account?

Difference between Abstract and Virtual classes
I am having trouble finding any documentation on:
1. What is the difference between Abstract and Virtual classes (they seem to be the exact same to me)
2. What are some scenarios for using Abstract or Virtual classes (wrapper classes comes to mind but are these the right thing to use?)
3. When would you use an Interface instead of an Abstract or Virtual? I read they are only suppose to be signatures but I saw an example that had a method with code in it too..
Hi Dena,
The basic difference between a virtual and abstratc class is that methods in virtual class CAN be overridden in derived classes, while abstract class methods MUST be overridden.
The following link gives a good example of when we use Interface vs abstract, go through when you get a chance :
http://social.msdn.microsoft.com/Forums/en-US/8ad621b8-a915-4d7e-89c3-5dbbc47202fd/whats-the-difference-between-abstract-classes-and-interfaces
Hope this helps!
abstract classes can contain methods that don't require an override and methods that do require an override, since it can contain methods that do require and override it must be extended to be constructed. useful if you want to share code among several closely related classes that impliment a common interface
virtual classes do not require any methods to be overriden and can be constructed as is without the need of extending.
http://share-salesforce.blogspot.com/2013/05/salesforce-apex-class-simpleregular-vs.html
is looking like same.
Using virtual the child class getting method value from parent class using super keyword(super.m();) and override in method function.
abstract class is a class
method has NO body, declare has ABSTRACT
* if class contains at least one abstract method
declare class has ABSTRACT
and it interact with child class with using override function
parent class
eg:
public abstract class abscl {
public void m1(){ // Defined and Implemented
System.debug(' I am in abscl: m1');
}
Public void m2(){ // Defined not implemented
}
public abstract void m3(); // Declared: Not Defined and Not Implemented this should be declared abtract method not implemented body method.
}
child class
public class abschd extends abscl{
public override void m3(){ // the abstract method should be declared in child class using override but object is created in child class only.
System.debug('I am in absch: m3 ');
}
}
virtual class
child class interact with parent class using extend keyword
Abstract Classes must be extended and all abstract methods MUST be overridden.
Virtual class are functional classes and can be instantiated or extended without then need of overriding methods.
you CANNOT do this
MyAbstract absImpl = new MyAbstract();
or
class MyNewClass extends MyAbstract {}
but you can do this:
MyVirtual vertImpl = new MyVirtual();
class MyNewClass extends MyVirtual {}
{
public b()
{
system.debug('welcom);
}
private abstract void c();
public class d extends a
{
private override void c()
{
system.debug('country');
}
}
program will come error :-that one constructor invalies:
am clearly expalin abstract class.....in simple of (Parent child relation );
we know that relation ,,but in programately system understands..language
for exmple:-
public abstract class Dena (// declaraction of class in U r name u r elder in ur family)
{
public abstract void nooneelder()( u only one person elder no one is there)
{
public mother extends Dena (/// this one ur supporting famiy member of mother)
{
void nooneelder()
{
system.debug('u r loveing mother');
go to object declaraction and complile it
this is simple of abstract class
The abstract definition modifier declares that this class contains abstract methods, that is, methods that only have their signature declared and no body defined.
Refer https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining.htm for more derails.
The abstract definition modifier declares that this class contains abstract methods, that is, methods that only have their signature declared and no body defined.
Refer https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_defining.htm for more derails.
Hello,
I create some brief description of abstract and virtual classes.
Interface
Abstract
- To create abstract class, we need to use abstract definition modifier.
- Allow to extend the child class.
- Abstract class can contain methods signed as abstract, to clarify, it is a method that has only a signature (body is not defined).
- Child class must implement all methods declared as abstract!
- Abstract class can also include other methods, which have the logic. To allow child class access those methods use protected or public keyword.
- Cannot be initialize directly: new TestAbstractClass():
- Abstract class can contain both virtual and abstract methods.
- Abstract class is some kind of “partial” class. Therefore, some methods are implemented, some needs to be implemented by child class.
- virtual methods can be override, but this is not mandatory.
- We can have different signatures for our methods:
- private – child class doesn’t have access to method signed as private.
- protected – child class has access to parent class method, but any other class doesn’t have access.
- public – In other words, making method accessible by any other class.
VirtualMore details you can find here (https://salesforceprofs.com/abstract-virtual-interface-in-apex/).