Posted by: Sourav | August 6, 2016

Inheritance and the usage of mybase and myclass in VB


Option Strict On
Imports System

Module Module1

Sub Main()
Dim emp1 As Employee = New FullTimeEmployee(“Sourav”, “Bhattacharya”, “allsourav2@gmail.com”, 50000)
’emp1.firstname = “Sourav”
’emp1.lastname = “Bhattacharya”
’emp1.email = “allsourav2@gmail.com”
‘ emp1.yearlysal = 50000
emp1.printfullname()

emp1 = New PartTimeEmployee
‘ emp1.firstname = “Sougata”
‘ emp1.lastname = “Bhattacharya”
‘ emp1.email = “allsourav2@gmail.com”
‘  emp1.yearlysal = 50000
emp1.printfullname()

Console.ReadLine()

End Sub

 

 

Public Class Employee
Protected firstname As String
Protected lastname As String
Protected email As String
Shared Sub New()
Console.WriteLine(“Hello I am parent class constructor”)
End Sub
Sub printfullname()
System.Console.WriteLine(“the fullname is {0} {1}”, Me.firstname, Me.lastname)

End Sub

End Class

 

 

Public Class FullTimeEmployee
Inherits Employee
Private yearlysal As Single
Sub New(Optional ByVal firstname As String = “John”, Optional ByVal lastname As String = “Doe”, Optional ByVal email As String = “john@fake.com”, Optional ByVal yearlysal As Single = 0.0)
MyBase.firstname = firstname
MyBase.lastname = lastname
MyBase.email = email
MyClass.yearlysal = yearlysal
End Sub

End Class

 

 

 

Public Class PartTimeEmployee
Inherits Employee
Private hourlysal As Single
Sub New(Optional ByVal firstname As String = “Jane”, Optional ByVal lastname As String = “Doe”, Optional ByVal email As String = “john@fake.com”, Optional ByVal hourlysal As Single = 0.0)
MyBase.firstname = firstname
MyBase.lastname = lastname
MyBase.email = email
MyClass.hourlysal = hourlysal
End Sub
End Class

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Categories

%d bloggers like this: