Inheritance
A key feature of OOP is reusability. It's always time saving and useful if we can reuse something that already exists rather than trying to create the same thing again and again. Reusing the class that is tested, debugged and used many times can save us time and effort of developing and testing it again. Once a class has been written and tested, it can be used by other programs to suit the program's requirement. This is done by creating a new class from an existing class. The process of deriving a new class from an existing class is called Inheritance. The old class is called the base class and the new class is called derived class. The derived class inherits some or everything of the base class. In Visual Basic we use the Inherits keyword to inherit one class from other. The general form of deriving a new class from an existing class looks as follows:
Public Class One
---
---
End Class
Public Class Two
Inherits One
---
---
End Class
Using Inheritance we can use the variables, methods, properties, etc, from the base class and add more functionality to it in the derived class. The following code demonstrates the process of Inheritance in Visual Basic.
Imports System.Console
Module Module1
Sub Main()
Dim ss As New Two()
WriteLine(ss.sum())
Read()
End Sub
End Module
Public Class One
'base class
Public i As Integer = 10
Public j As Integer = 20
Public Function add() As Integer
Return i + j
End Function
End Class
Public Class Two
 Inherits One
'derived class. class two inherited from class one
Public k As Integer = 100
Public Function sum() As Integer
'using the variables, function from base class and adding more functionality
Return i + j + k
End Function
End Class
Output of above code is sum of i, j, k as shown in the image below.
Popular Posts
-
Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his...
-
Accessing the Standard CGI Variables: To build the successful web application, you often need to know a lot about the environment in which ...
-
INTRODUCTION TO 'C': C is a programming language developed at AT & T's Bell laboratories of USA in 1972.it was designed by d...
-
SQL aliases can be used with database tables and with database table columns, depending on task you are performing. SQL column aliases are u...
-
Learning about Events (Continue) Lets program the Form_Load event. "MsgBox" is Visual Basic command that launch a message box. for...
-
Steps to follow: 1. Write Person.java as shown below in Code-11.3.a under polypackage directory. (You are welcome to do this work using eit...
-
The Command Button's KeyPress, KeyDown and KeyUp Events The events that will be mentioned in the following pages are commonly used, and ...
-
The SQL AVG aggregate function selects the average value for certain table column. Have a look at the SQL AVG syntax: SELECT AVG(Column1) FR...
-
package interfaceexercise; // Define an interface with three abstract methods. // Any class that implements this interface has to // impleme...
-
We will use the Customers table to illustrate the SQL LIKE clause usage: FirstName LastName Email DOB Phone John Smith John.Smith@yaho...
No comments:
Post a Comment