In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly shows you "VB.NET how to achieve inheritance class", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "VB.NET how to achieve inheritance class" this article.
VB.NET inheritance class is a feature that allows you to extend the class, if you need some functionality, you can create a new class, if part of the function you need can already be provided by an existing class, you can extend the original class to build a new class. Then the new class you create becomes a subclass or VB.NET inherited class, and the original class is called the parent class or the base class. The process of extending a class is called extension, and the term subclass or inherit is sometimes used to describe the behavior of an extended class. In VB.NET, a class can have only one parent class, and multiple parent classes are not allowed.
In syntax composition, declare an extension class to use a semicolon after the class name, followed by a semicolon and the parent class name. For example, the extension class Employee creates a new class Manager, as follows
Listing 9: Extending a class Imports System Class Employee Dim salary As Decimal = 40000 Dim yearlyBonus As Decimal = 4000 Public Sub PrintSalary () 'print the salary to the Console Console.Write (salary) End Sub End Class Class Manager: Inherits Employee End Class
If the word Inherits is displayed on the next line, you do not need a semicolon, such as:
Class Manager Inherits Employee End Class
Now you can initialize a Manager object, using the members of the Manager object, such as the following code
Class Employee Public salary As Decimal = 40000 Public yearlyBonus As Decimal = 4000 Public Sub PrintSalary () 'print the salary to the Console Console.Write (salary) End Sub End Class Class Manager: Inherits Employee End Class Module Module1 Public Sub Main () Dim manager As Manager manager = New Manager () manager.PrintSalary () End Sub End Module
The following example shows adding a new method PrintBonus to the manage class
Class Manager: Inherits Employee Public Sub PrintBonus () Console.Write (yearlyBonus) End Sub End Class
Note the use of member access restrictions, for example, if the yearlyBonus field is set to private, then the manage class cannot access him, otherwise the wrong conclusion will be drawn at compile time.
The VB.NET inheritance class is just a common practice. In fact, the. NET Framework class library consists of different levels of classes that inherit from other classes For example, the button class in the Windows.Forms namespace is a subclass of the ButtonBase class, while the ButtonBase class itself is a subclass of the Control class, and all classes end up with System.Object as their root, and System.Object is also called a root or superclass in the .NET Framework class library.
Public Class MyForm: Inherits System.Windows.Forms.Form
End Class
The blank class declared is compiled and executed to generate a windows form. You can create a form without writing a single line of code, because myform inherits from System.Windows.Forms.Form, and he also inherits the functions of form.
These are all the contents of the article "how to implement inheritance classes in VB.NET". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.