Professional Documents
Culture Documents
Ranotkar
Practical no. 18
XI. Program Code: (Teacher must assign separate program statement to group of 3-4
student)
A) Constructor-
Module Module1
Sub Main()
obj.show()
Console.ReadLine()
End Sub
End Function
Sub New()
Console.WriteLine(“Constructor Executed”)
End Sub
End Class
End Module
B) Destructor-
Module Module1
Sub Main()
obj.show()
End Sub
End Module
End Function
Console.ReadLine()
End Sub
End Class
A) Constructor–
Constructor Executed
B) Destructor–
Imports System.Console
Module Module1
Sub Main()
WriteLine(con.ShowAge()) Read()
End Sub
End Module
End Sub
Return Age
Imports System.Console
Module Module1
Sub Main()
End Module
Write(“VB.NET”)
Read()
End Sub
End Class
Ans: 40
Imports System.Console
Module Module1
Sub Main()
End Sub
End Module
Write(“VB.NET”)
Read()
End Sub
End Class
Ans:
Warning 2 variable ‘Finalize’ conflicts with sub ‘Finalize’ in the base class ‘Object’
and should be declared ‘Shadows’.
XIV. Exercise (Teacher must assign separate exercise to group of 3-4 student)
Module Module1
Sub Main()
obj.display()
Console.ReadLine()
End Sub
Class sample
Console.WriteLine(“This is Constructor”)
End Sub
Sub display()
Console.WriteLine(“This is Method”)
End Sub
End Class
End Module
Output:
Module Module1
Sub Main()
obj.area()
Console.ReadLine()
End Sub
Class circle
Dim r, a As Double
r=i
End Sub
Sub area()
a=p*r*r
End Sub
End Class
End Module
OUTPUT:
Practical no. 19
XI. Program Code: (Teacher must assign separate program statement to group of 3-4
student)
Module Module1
Sub Main()
obj.show()
Console.ReadLine()
End Sub
End Module
End Class
Inherits student
Return 0
End Function
End Class
Branch = Computer
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
sub New()
End sub
End class
Sub New()
MyBase.New()
End sub
End class
Ans:
My Base Class
My Child Class
Get
End Get
End Property
End Class
End Class
Ans:
Warning2: Property ‘FullName’ doesn’t return a value on all code paths. A null reference
exception could occur at run time when the result is used.
Error3: Statement cannot appear within a method body. End of method assumed.
XIV. Exercise (Teacher must assign separate exercise to group of 3-4 student)
Implement a Program for inheritance where Student is Child class and faculty is Base (Take
Appropriate variables in Base and child class)
1. Implement a program for inheritance where Student is Child Class and faculty is Base
class.(Take Appropriate variable in Base and Child class)
Module Module1
Sub Main()
s.branch()
s.year()
Console.ReadLine()
End Sub
Class faculty
Sub branch()
Console.WriteLine(“Branch = ” & b)
End Sub
End Class
Class student
Inherits faculty
Sub year()
Console.WriteLine(“Year = ” & y)
End Sub
End Class
End Module
Output:
Overloading:
Module Module1
Sub Main()
Console.WriteLine(res.add(10))
Console.WriteLine(res.add(35, 20))
Console.ReadLine()
End Sub
End Module
Public i, j As Integer
Return i
End Function
Return i + j
End Function
End Class
Overriding:
Module Module1
Sub Main()
result = obj.add(10, 5)
Console.ReadLine()
End Sub
End Module
Return (i + j)
End Function
End Class
Inherits parent
Return (i + j)
End Function
End Class
Overloading:
10
55
In the above overloading example the same function add is called to perform different
operations based on different arguments.
Overriding:
Result =15
In the above overriding the parent class function add is overridden in the child class
using the MyBase.add(12, 18) statement. So first the overridden value is displayed, then the
value from child class is display.
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
Imports System
Module Module1
Class overload
Dim r As Double
Console.WriteLine(1 / 3 * 3.14 * r * r * r)
End Sub
Console.WriteLine(length * width)
End Sub
End Class
Sub Main()
r.area(3.1)
r.area(4, 5)
End Sub
End Module
Answers
a.name = "ABC"
a.address = "Arvi dist.wardha"
a.EmpId = 123
a.salary = 25000
a.JoinDate = "12 - 4 - 2020"
a.ShowInfo()
End Sub
Public Class EmpPersonalDetails
Public name As String
Public address As String
Public Overridable Sub ShowInfo()
MessageBox.Show("Employee Name" & name)
MessageBox.Show("Employee Address" & address)
End Sub
End Class
Public Class EmpInfo
Inherits EmpPersonalDetails
Public EmpId As Integer
Public salary As Integer
Public JoinDate As Date
Overloads Sub ShowInfo()
MyBase.ShowInfo()
MessageBox.Show("Employee ID" & EmpId)
MessageBox.Show("Employee Salary" & salary)
MessageBox.Show("Employee Joining Date" & JoinDate)
End Sub
End Class
End Class
OUTPUT:
XIV. Exercise (Teacher must assign separate exercise to group of 3-4 student)
End Class
Output:
Practical no. 22
XI. Program Code: (Teacher must assign separate program statement to group of 3-4
student)
Module Module1
Sub Main()
p.use()
c.use()
Console.WriteLine(“________________________________”)
p.disp()
c.disp()
Console.ReadLine()
End Sub
Console.WriteLine(“Parent”)
End Sub
Me.disp()
End Sub
End Class
Inherits parent
Console.WriteLine(“Child”)
End Sub
End Class
End Module
Parent
Parent
________________________________
Parent
Child
Note: Below given are few sample questions for reference. Teacher must design more such
questions so as to ensure the achievement of identified CO.
Shared x As Integer = 1
Dim x As Integer = 10
Console.WriteLine(“main: x” & x)
End Sub
End Class
Ans:
Dim x As Integer = 10
Dim x As Integer = 30
MsgBox(x)
End Sub
End Class
Ans:
Error 1 : Handles clause requires a WithEvents variable defined in the containing type or
one of its base types.
XIV. Exercise (Teacher must assign separate exercise to group of 3-4 student)
Module Module1
Sub Main()
f.display()
s.display()
t.display()
Console.ReadLine()
End Sub
End Module
End Sub
End Class
Inherits first
End Sub
End Class
Inherits second
End Sub
End Class
OUTPUT: