Shivprasad Koirala
.NET and OOPS interview questions - How will you define abstract classes?
By Shivprasad Koirala in ASP.NET on Jul 06 2011
  • Mehul Prajapati
    Jan, 2018 27

    If a class is defined as abstract then we can't create an instance of that class. By the creation of the derived class object where an abstract class is inherit from, we can call the method of the abstract class.

    • 1
  • Vishal Jadav
    Sep, 2016 12

    Abstract class is used to define common functionalities in a distributed environment.

    • 0
  • sridhar thota
    May, 2015 24

    Abstract Class: Abstract class is a base class from which a derived classes can get inherited. If we want a method to be overridden in all child classes then we have to declared that method as abstract method. If a class contains at least one abstract method then that class must be declared as abstract class. Abstract class can contain both abstract and non abstract methods. Abstract class can implement more than one interface. The implementation of abstract methods should be provided in the class that is inheriting abstract class.

    • 0
  • Adit Pattanayak
    Nov, 2014 1

    The abstract keyword is used to create abstract classes. An abstract class is incomplete and hence cannot be instantiated. An abstract class can only be used as base class. An abstract class cannot be sealed. Abstract class may contain abstract members, but not mandatory. A non abstract class derived from an abstract class must provide implementation for all inherited abstract members.If a class inherit from an abstract class there are 2 options available for that class1) Provide implementation for all the abstract members inherited from the base abstract class2) If the class does not wish to provide implementation for all the abstract members inherited from the abstract class, then the class has to be marked as abstract.

    • 0
  • johnpaulmathew
    Jul, 2011 16

    Abstract classes are one of the essential behaviors provided by .NET. Commonly, you would like to make classes that only represent base classes, and don't want anyone to create objects of these class types. You can make use of abstract classes to implement such functionality in C# using the modifier 'abstract'.

    ______________________________________________________________
    Abroad Consultants in India

    • 0
  • suryaprasath g
    Jul, 2011 14

    Abstract Classes

    An abstract class is the one that is not used to create objects. An 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 it's own, it must be inherited. Like interfaces, abstract classes can specify members that must be implemented in inheriting classes. Unlike interfaces, a class can inherit only one abstract class. Abstract classes can only specify members that should be implemented by all inheriting classes.


    More Details : Abstract

    • 0
  • Shivprasad Koirala
    Jul, 2011 6

     
    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 inherited.
       
    • 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:

     

    • 0


Most Popular Job Functions


MOST LIKED QUESTIONS