ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the 'Friend' keyword

Here, we are going to demonstrate the 'Friend' keyword in VB.Net.
Submitted by Nidhi, on December 30, 2020

Here, we will create a subroutine or procedure with the Friend keyword. The Friend keyword is used to limit the scope a method, Friend method or subroutine cannot be accessed outside the same assembly.

Program/Source Code:

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

'VB.net program to demonstrate the "Friend" keyword.

Class Sample
    ' The Fun() is public if we are in the same assembly.
    Friend Sub Fun()
        Console.WriteLine("Friend function Fun() called")
    End Sub
End Class

Module Module1
    Sub Main()
        Dim obj As New Sample()
        obj.Fun()
    End Sub
End Module

Output:

Friend function Fun() called
Press any key to continue . . .

Explanation:

In the above program, we created a class Sample that contains a Friend method, which can only be accessed within the same assembly.

After that, we created a module Module1 that contains the Main() method, the Main() method is the entry point for the program. And, we created the object of the Sample class and then called the Fun() method, which will print the appropriate message on the console screen.

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.