PWVB-LecturesNotesNo 10
PWVB-LecturesNotesNo 10
Department of Mathematics
and Computer Science
1
Agenda
▪ Arrays in VB .NET ▪ Example 5, 6, 7: Using Class and Objects
▪ Creating Arrays in VB .NET ▪ Inheritance in VB.NET
▪ Initializing Arrays in VB .NET ▪ Visual Illustration of Inheritance
▪ Example 1: Integer arrays ▪ General form of inheritance
▪ Example 2: String arrays ▪ Example 8 ,9, 10: Implementation of Inheritance
▪ Functions in VB .NET ▪ Types of Inheritance in VB.NET
▪ Function Return Methods in VB .NET ▪ Visual Illustration of Single Inheritance
▪ Example 3: Return by Using Return Statement ▪ Example 11: Implementation of Single Inheritance
▪ Example 4: Return by Assigning to Function Name ▪ Visual Illustration of Multilevel Inheritance
▪ Introduction to OOP in VB .NET ▪ Example 12: Implementation of Multilevel Inheritance
▪ Fundamentals of OOP: Classes and Objects ▪ Visual Illustration of Hierarchical Inheritance
▪ OOP: Data Hiding and Methods ▪ Example 13: Implementation of Hierarchical Inheritance
▪ Visual Illustration of OPP ▪ Interfaces in VB.NET
▪ Advantages of OOP ▪ Example 14, 15: Implementation of Interface
▪ Defining a Class in Visual Basic ▪ References
Arrays
2
Arrays
Arrays
Initializing Arrays in VB .NET ▪ You can also initialize the array elements while
declaring the array
3
Arrays
Arrays
4
Functions
Functions in VB .NET
▪ A Function is a type of procedure that returns a value to the
calling code after execution, unlike Subs which do not return
values.
▪ Functions are declared using the Function statement,
specifying the function name, parameters (optional), and
return type.
▪ The syntax for defining a function is:
Statements . . .
End Function
Functions
5
Arrays
Arrays
Module Module1
Example 4: Return Sub Main()
by Assigning to Dim a As Integer = 100
Function Name Dim b As Integer = 200
Dim res As Integer
res = FindMax(a, b)
Console.WriteLine("Max value is : {0}", res)
This example Console.ReadLine()
explains how to use End Sub
Function FindMax(num1 As Integer, num2 As Integer) As Integer
function with return Dim result As Integer
by assigning to If (num1 > num2) Then
function name result = num1
Else
result = num2
End If
FindMax = result
End Function
End Module
6
Object Oriented
Programming in VB
.NET
Object-Oriented Programming
7
Object-Oriented Programming
Object-Oriented Programming
8
Object-Oriented Programming
Visual
Illustration of
OPP
Object-Oriented Programming
Visual
Illustration of
OPP
9
Object-Oriented Programming
Class Box
Private a as Integer
Public x As String
Visual Public func() As String
.
Illustration of .
OPP End Class
Object-Oriented Programming
Advantages of OOP
Real-World Enables the use of real-world modeling (e.g., a car
Modeling is an object that has attributes, such as an
engine, wheels, etc).
10
Object-Oriented Programming
Class Student
Dim Name As String = "Ahmed" 'String data
Dim Age As Integer = 30 'Integer data
Public Sub showInfo() 'a function
Console.WriteLine("Name is: {0}", Name)
Console.WriteLine("Age is: {0}", Age)
End Sub
End Class
Object-Oriented Programming
11
Object-Oriented Programming
Object-Oriented Programming
12
Inheritance in OOP
Inheritance in VB.NET
▪ Inheritance is the ability of a class to
inherit/derive properties and characteristics
of another class.
Inheritance in OOP
Visual
Illustration of
Inheritance
13
Inheritance in OOP
'derived_class base_class
Class myclass2 : Inherits myclass1
'Members of derived class here
End Class
Inheritance in OOP
14
Inheritance in OOP
Inheritance in OOP
15
Inheritance in OOP
Derived class inherits from Derived class inherits from a More than one derived Defines method declarations
only one base class. The class which itself is derived classes inherit from a single without implementation.
child class has a single from another class, forming base class, creating a Allows multiple inheritance
parent class. a chain of inheritance. hierarchy of child classes by implementing multiple
from one parent. interfaces.
Inheritance in OOP
▪ Single Inheritance happens when derived class is allowed to
inherit from only one base class (the child class has only one
parent class).
Visual
Illustration of
Single
Inheritance
16
Inheritance in OOP
Inheritance in OOP
▪ Multilevel Inheritance happens when a derived class inherits all
its properties from a class that itself inherits from another class
(a child class has a parent that itself a child for another class).
Visual
Illustration of
Multilevel
Inheritance
17
Inheritance in OOP
Inheritance in OOP
▪ Hierarchical Inheritance: happens when multiple derived classes
inherit their properties from just a single base class (multiple
child classes has the same parent classes).
Visual
Illustration of
Hierarchical
Inheritance
18
Inheritance in OOP
Inheritance in OOP
Interfaces in VB.NET
19
Inheritance in OOP
Inheritance in OOP
20
References
References
▪ https://www.tutorialspoint.com/vb.net/vb.net_loops.htm
▪ Internet
21