17
17
17
Module Program
Public Class studet
Dim rollno As Integer
Dim name As String
Dim marks As Decimal
Function getdata()
Console.WriteLine("Enter roll no : ")
rollno = Console.ReadLine()
Console.WriteLine("Enter name : ")
name = Console.ReadLine()
Console.WriteLine("Enter marks : ")
marks = Console.ReadLine()
End Function
Function display()
Console.WriteLine("****************Enter Student
Information************")
Console.WriteLine("Roll no = {0}", rollno)
Console.WriteLine("name = {0}", name)
Console.WriteLine("marks = {0}", marks)
End Function
End Class
Sub Main()
Dim s1 As New studet()
Dim s2 As New studet()
s1.getdata()
s2.getdata()
s1.display()
s2.display()
End Sub
End Module
Parameterised constructor
Imports System
Module Program
bookid = id
bookname = name
bookprice = price
End Function
Function display()
Console.WriteLine("*********Book Information***************")
End Function
End Class
Sub Main()
b1.display()
End Sub
End Module
Default Constructor
Imports System
Module Program
Public Class vechicle
Sub New()
Console.WriteLine("Constructor called successfully!")
End Sub
Sub display()
Console.WriteLine("This is sub procedure")
End Sub
End Class
Sub Main(args As String())
Dim v1 As New vechicle()
v1.display()
End Sub
End Module
Parameterised Constructor
Imports System
Module Program
Public Class vechicle
Dim vechicleno As String
Sub New(vno As String)
vechicleno = vno
Console.WriteLine("Constructor called successfully!")
End Sub
Sub display()
Console.WriteLine("vechicle no is {0}", vechicleno)
End Sub
End Class
Sub Main()
Dim v1 As New vechicle("MH14gh3423")
v1.display()
End Sub
End Module
Constructor Oveloading
Imports System
Module Program
Public Class vechicle
Dim vechicle_number As String
Sub New(vn As String)
vechicle_number = vn
Console.WriteLine("Constructor called successfully!")
End Sub
Sub New()
vechicle_number = "hfks3344"
Console.WriteLine("Constructor called successfully!")
End Sub
Sub display()
Console.WriteLine("vechicle no is {0}", vechicle_number)
End Sub
End Class
Sub Main()
Dim v1 As New vechicle("MH14gh3423")
Dim v2 As New vechicle()
v1.display()
v2.display()
End Sub
End Module
Inheritance
Imports System
Module Program
Sub Main()
Dim b1 As New B
b1.test
b1.hello
b1.hello("hello world!")
End Sub
Public Class A
Public Overridable Sub test()
Console.WriteLine("This is inside test!")
End Sub
End Class
Public Class B
Inherits A
Public Overrides Sub test()
Console.WriteLine("This is overridable version of test")
Console.ReadLine()
End Sub
Public Sub hello()
Console.WriteLine("Hello")
Console.ReadLine()
End Sub
Public Sub hello(ByVal s1 As String)
Console.WriteLine(s1)
Console.ReadLine()
End Sub
End Class
End Module
Constructor – destructor
Imports System
Module Program
Class sample
Sub New()
Console.WriteLine("Constructor called!")
End Sub
Protected Overrides Sub Finalize()
Console.WriteLine("Destructor called!")
MyBase.Finalize()
End Sub
End Class
Sub Main(args As String())
Dim d1 As New sample
D1.new()
End Sub
End Module
End Sub
Custom exception
program
Public Class MyCustomException
Inherits System.Exception
Public Sub New()
MyBase.New("An error occurred in the MyCustomException class.")
End Sub
Module1
Public Class Program
Public Shared Sub Main()
Try
' Some code that might throw the custom exception...
Throw New MyCustomException("Custom exception message")
Catch ex As MyCustomException
Console.WriteLine("Custom exception caught: " & ex.Message)
Catch ex As Exception
Console.WriteLine("An unexpected error occurred: " & ex.Message)
End Try
End Sub
End Class
errorprovider