Abstract Class Interview Questions


–         The abstract modifier can be used with classes, methods, properties, indexers, and events
–         An abstract class cannot be instantiated
–         It is an error to use the static or virtual modifiers in an abstract method declaration.
–         An abstract method is implicitly a virtual method
–         Abstract method declarations are only permitted in abstract classes.
–         The implementation is provided by an overriding method, which is a member of a non-abstract class
–         Use the abstract modifier in a method or property declaration to indicate that the method or property does not contain implementation
–         An abstract class that implements an interface might map the interface methods onto abstract methods

Abstract can be Sealed or Static?
No. Because Sealed speccify that the class can not be inherit. Same way static classes are Sealed class that also can not be inherited.

What is difference between Abstract and Virtual?

– Virtual method has the implentation other hand abtract mthod does not have.

– Virtual mthod provide the option of overriding it other hand abstract method forced to override it.

– Virtual method provide own implementation in inherited class using override and base class contains own implementation other hand abstract class implemented only in chil (inherited0 class.

See the below example for all scenarios:

public abstract class AbsClass     
{  
       public abstract void AbsWork();
       public virtual int VirtualWork() 
      {             return 100;         }
}
public class ChildClass: AbsClass
{
         public override void AbsWork() 
        { 
            //Abstract method implentation 
        }  
    public override int VirtualWork() 
       {             //Virtual method override
             return 200;
       }
}

 

Please let me know if you have any concern about abstract and virtual implementation.

Advertisements
Tagged with: , , ,
Posted in .Net, Asp.Net, C#

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Top Rated

Error: Please make sure the Twitter account is public.

Blog Stats
  • 30,188 hits
%d bloggers like this: