.NET and OOPS interview questions – Give a brief on abstract classes?

In the following manner we can describe abstract class: –

  • We can not create a object of abstract class.
  • Abstract class is designed to act as a base class (to be inherited by other classes). Abstract class is a design concept in program development and provides a base upon which other classes are built.
  • Abstract classes are similar to interfaces. After declaring an
    abstract class, it cannot be instantiated on its own, it must be
  • In VB.NET, abstract classes are created using “MustInherit”
    keyword.In C# we have “Abstract” keyword.
  • Abstract classes can have implementation or pure abstract methods, which should be implemented in the child class.

From interview point of view, just saying using “Must Inherit” keyword is more than enough to convince that you have used abstract classes. But to clear simple fundamental let us try to understand the sample code. There are two classes one is “ClsAbstract” class and other is “ClsChild” class. “ClsAbstract” class is a abstract class as you can see the mustinherit keyword. It has one implemented method “Add” and other is abstract method, which has to be implemented by child class “Multiply Number”. In the child class, we inherit the abstract class and implement the multiply number function.

Definitely, this sample does not take out actually how things are
implemented in live projects. You put all your common functionalities or half implemented functionality in parent abstract class and later let child class define the full functionality of the abstract class. Example we always use abstract class with all my SET GET properties of object in abstract class and later make specialize classes for insert, update, delete for the corresponding entity object.

Public MustInherit Class ClsAbstract
‘Use the mustinherit class to declare the class as abstract
Public Function Add(ByVal intnum1 As Integer, ByVal intnum2 As Integer) As Integer
Return intnum1 + intnum2
End Function
‘Left this second function to be completed by the inheriting class
Public MustOverride Function MultiplyNumber(ByVal intnum1 As Integer, ByVal intnum2 As Integer) As Integer
End Class
Public Class ClsChild
Inherits ClsAbstract
‘ class child overrides the Multiplynumber function
Public Overrides Function MultiplyNumber(ByVal intnum1 As Integer, ByVal intnum2 As Integer) As Integer
Return intnum1 * intnum2
End Function
End Class

Following is the output snapshot for the above code:

My attitude towards abstract class has been that i put all my common
functionality in abstract class.

Following you can also view video on different types of collections
available in .NET:

Please click here to see more .NET/OOPS interview questions


Visit Authors blog for more .NET and OOPS interview questions

About c# and .NET Interview questions

This blog is for developers who want to crack .NET and C# interviews. It has all tips and tricks needed to crack .NET interviews , C# interview , SQL Server interview , Java interview , WCF Interview , Silverlight interview , WPF interview , LINQ interview , Entity framework Interview. Do not forget to watch our Learn step by step video series. Learn MVC in 16 hours:- https://www.youtube.com/watch?v=Lp7nSImO5vk Learn AngularJS Step by Step:- https://www.youtube.com/watch?v=0kmdjqgO9IY Learn Design Pattern in 8 hours:- https://www.youtube.com/watch?v=YDobmucohqk Learn C# and .NET in 60 days:- https://www.youtube.com/watch?v=yh2SrzCkNQA Learn MSBI in 32 hours:- https://www.youtube.com/watch?v=mGPJx3ocFgg Learn SharePoint Step by Step in 8 hours:- https://youtu.be/C2fW76SwJNU
This entry was posted in Uncategorized and tagged , , , , , , . Bookmark the permalink.

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s