Você está na página 1de 3

This document contains: Function overloading Classes and objects Multilevel inheritance Must inherit inheritance Multiple inheritance

ance Abstract class Constructor and destructors Create a form with five buttons:

Code:Public Class methodoverload 'method overloading starts Public Function alok() Return "function with no argument" End Function Public Function alok(ByVal str As String) Return "function takes 1 argument " + str End Function Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click MessageBox.Show(alok()) Dim s As String = InputBox("enter a string to call function") MessageBox.Show(alok(s)) End Sub 'method overloading end

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click 'calling class first and second sub procedures using class first object Dim obj As New second obj.abc() obj.def() End Sub Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click Dim obj As New four obj.must() End Sub Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click Dim obj As New a obj.disp() Dim obj1 As New b obj1.disp() End Sub

Private Sub Button5_Click(sender As Object, e As EventArgs) Handles Button5.Click Dim obj As a1 = New a1(57) Dim obj1 As a1 = New a1 Dim obj2 As a1 = New a1 MessageBox.Show(obj.sum.ToString) End Sub End Class 'multilevel inheritance starts first of all create two classes' Public Class first 'create a sub procedure but it should be declared as public Public Sub abc() MessageBox.Show("class first") End Sub End Class Public Class second Inherits first 'now here we inherits class first into second to access the member function of first into second Public Sub def() MessageBox.Show("class second") End Sub End Class 'multilevel inheritance ends...

'mustinherit starts - we can't create class object if class is declared as mustinherit we can only use as base class Public MustInherit Class third Public Sub must() MessageBox.Show("we can't create class object if class is declared as mustinherit ") End Sub End Class

Public Class four Inherits third End Class 'mustinherit ends

'multiple inheritance for this we have to use interfaces

Public Class a Implements alok Sub disp() Implements alok.disp MessageBox.Show("class a") End Sub End Class Public Class b Implements alok Sub disp() Implements alok.disp MessageBox.Show("class b") End Sub End Class Interface alok Sub disp() End Interface 'multiple inheritance ends....'

'constructor and destructor Public Class a1 Public id As String Public Sub New(strTextBox As String) id = (strTextBox) End Sub Dim i As Integer = 9 Public Function sum() Return id End Function Public Sub New() MessageBox.Show("default constructor") End Sub Protected Overrides Sub finalize() MessageBox.Show("deallocated") 'this will dellocates all the objects of a1 when we close the form' End Sub End Class

'constructor and destructor ends'

Você também pode gostar