Categories:
.NET (357)
C (330)
C++ (183)
CSS (84)
DBA (2)
General (7)
HTML (4)
Java (574)
JavaScript (106)
JSP (66)
Oracle (114)
Perl (46)
Perl (1)
PHP (1)
PL/SQL (1)
RSS (51)
Software QA (13)
SQL Server (1)
Windows (1)
XHTML (173)
Other Resources:
What are abstract classes
What are abstract classes ?
✍: Guest
Following are features of a abstract class :-
ã You 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 gMustInherith keyword.In C#
we have gAbstracth 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 “MustInherit” keyword is more than enough
to convince that you have used abstract classes. But to clear simple fundamental let’s 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 “MultiplyNumber”. In the child class we
inherit the abstract class and implement the multiplynumber function.
Definitely this sample does not take out actually how things are implemented in live
projects. Basically 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 i 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 seconf 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
2007-10-23, 5279👍, 0💬
Popular Posts:
What will be printed as the result of the operation below: main() { int a=0; if (a==0) printf("Cisco...
Can two catch blocks be executed? No, once the proper catch section is executed the control goes fin...
What is NullPointerException and how to handle it? When an object is not initialized, the default va...
What is the benefit of using #define to declare a constant? Using the #define method of declaring a ...
How to create a thread in a program? You have two ways to do so. First, making your class "extends" ...