ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the MyBase keyword

Here, we are going to demonstrate the MyBase keyword in VB.Net.
Submitted by Nidhi, on December 28, 2020

Here, we will create a base class Sample1 and then inherit Sample1 class into Sample2 class. Then we will call the base class method using the MyBase keyword.

Program/Source Code:

The source code to demonstrate the MyBase keyword is given below. The given program is compiled and executed successfully.

'VB.net program to demonstrate the MyBase keyword.

Module Module1
    Class Sample1
        Sub Fun1()
            Console.WriteLine("Sample1.Fun1() called")
        End Sub
    End Class

    Class Sample2
        Inherits Sample1
        Sub Fun2()
            MyBase.Fun1()
            Console.WriteLine("Sample2.Fun2() called")
        End Sub
    End Class

    Sub Main()
        Dim S As New Sample2()
        S.Fun2()
    End Sub
End Module

Output:

Sample1.Fun1() called
Sample2.Fun2() called
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains two classes Sample1 and Sample2.

Both classes contain one method. Here, we inherited Sample1 class into Sample2 class. Then we called the base class method using the MyBase keyword from Sample2 class.

At last, we created a Main() function, which is the entry point for the program, here we created the object of Sample2 class, and called Fun2() that will call Fun1() method of Sample1 class.

VB.Net Basic Programs »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.