Oop Past Program
Oop Past Program
Console.ReadKey()
End Sub
End Module
Module Module1
MustInherit Class PV
Public regno As String
Public seats As Integer
Public Sub showregno()
Console.WriteLine(regno)
End Sub
Public Sub showseats()
Console.WriteLine(seats)
End Sub
End Class
Class bus : Inherits PV
End Module
Program 2 Inheritance
Module Module1
Class A
Protected bvalue As Integer
Class B : Inherits A
Public Sub New(ByVal value As Integer)
bvalue = value
End Sub
End Class
Class C : Inherits A
Public Sub New(ByVal value As Integer)
bvalue = value * 2
End Sub
End Class
Sub Main()
Dim b As B = New B(5)
b.Display()
Dim c As C = New C(5)
c.Display()
Console.ReadKey()
End Sub
End Module
Sub Main()
Dim table As Hashtable = New Hashtable
table.Add(100, "Perl")
table.Add(200, "Dot")
table.Add(300, "Net")
End Module
Module Module1
Sub Main()
Dim ht As Hashtable = New Hashtable()
Dim k As String
ht.Add("001", "Zara Ali")
ht.Add("002", "Abida Rehman")
ht.Add("003", "Joe Holzner")
ht.Add("004", "Mausam Benazir Nur")
ht.Add("005", "M. Amlan")
ht.Add("006", "M. Arif")
ht.Add("007", "Ritesh Saikia")
If (ht.ContainsValue("Nuha Ali")) Then
Console.WriteLine("This student name is already in the list")
Else
ht.Add("008", "Nuha Ali")
End If
' Get a collection of the keys.
Dim key As ICollection = ht.Keys
For Each k In key
Console.WriteLine(" {0} : {1}", k, ht(k))
Next k
Console.ReadKey()
End Sub
End Module
Program 5 (List)
Module Module1
Sub Main()
Dim list As New List(Of Integer)
list.Add(2)
list.Add(3)
list.Add(7)
' Loop through list elements.
Dim num As Integer
For Each num In list
Console.WriteLine(num)
Next
Console.readkey()
End sub
End module
Program 6 (List)
Module Module1
Sub Main()
Dim list As New List(Of Integer)
list.Add(2)
list.Add(3)
list.Add(7)
End Sub
End Module
Program 7 (List)
Module Module1
Sub Main()
End Sub
End Module
Program 8 (List)
Module Module1
Sub Main()
End Sub
End Module
Program 10 (Polymorphism)
Module Module1
Sub Main()
Dim two As New One()
Console.WriteLine(two.add(10))
'calls the function with one argument
Console.WriteLine(two.add(10, 20))
'calls the function with two arguments
Console.WriteLine(two.add(10, 20, 30))
'calls the function with three arguments
Console.ReadKey()
End Sub
Public Class One
Public i, j, k As Integer
Program 12 (polymorphism)
Module Module1
Public Class poly
Public Overridable Sub show()
Console.WriteLine("hello")
End Sub
End Class
Public Class poly2 : Inherits poly
Public Overloads Sub show()
Console.WriteLine("world")
End Sub
End Class
Sub Main()
Dim a As poly2 = New poly2()
a.show()
Console.ReadKey()
End Sub
End Module
Program 13 (polymorphism)
Module Module1
Public Class poly
Public Sub show()
Console.WriteLine("hello")
End Sub
End Class
Public Class poly2 : Inherits poly
Public Overloads Sub show()
Console.WriteLine("world")
End Sub
End Class
Sub Main()
Dim a As poly2 = New poly2()
a.show()
Console.ReadKey()
End Sub
End Module
Sub Main()
Call TryExample()
Console.ReadKey()
End Sub
Public Sub TryExample()
' Declare variables.
Dim x As Integer = 5
Dim y As Integer = 0
' Set up structured error handling.
Try
' Cause a "Divide by Zero" exception.
x = x \ y
' This statement does not execute because program
' control passes to the Catch block when the
' exception occurs.
Console.writeline("end of Try block")
Catch ex As Exception
' Show the exception's message.
Console.writeline(ex.Message)
End Module
Program (general)
Module Module1
Sub Main()
Dim two As New One()
Console.WriteLine(two.add(10))
'calls the function with one argument
Console.WriteLine(two.add(10, 20))
'calls the function with two arguments
Console.WriteLine(two.add(10, 20, 30))
'calls the function with three arguments
Console.ReadKey()
End Sub
Public Class One
Public i, j, k As Integer
Public Function add(ByVal i As Integer) As Integer
'function with one argument
Return i
End Function
Public Function add(ByVal i As Integer, ByVal j As Integer) As Integer
'function with two arguments
Return i + j
End Function
Public Function add(ByVal i As Integer, ByVal j As Integer, ByVal k As Integer)
As Integer
'function with three arguments
Return i + j + k
End Function
End Class
End Module