3.7.1 class and Object

Source: Internet
Author: User

1. Class
Class is the abstraction of things with the same attributes and actions. It is the most basic and core concept of object-oriented programming. Class encapsulates the static features of an object, that is, attributes) and dynamic behavior features, that is, operations or methods ).
Syntax:
Class Name
Class member declaration
End Class
Class Members include attributes, also known as fields) and methods. The following is the definition of a class Employee:
Class Employee
Dim salary As Decimal = 40000
Dim yearlyBonus As Decimal = 4000
Public Sub PrintSalary ()
Reponse. Write (salary)
End Sub
End Class
The class Employee has two fields salary and yearlyBonus. Their default values are 40000 and 4000 respectively. There is a method PrintSalary ().

2. Object
A class is a template for creating objects, and an object is a class instance. Objects in the objective world have their own properties and behaviors, such as cars. Their attributes include shape and color. Their behaviors include forward and backward. VB. NET objects also have their own attributes and methods and events. attributes are the properties of objects, and methods are the actions or actions of objects. VB. NET implements various functions by programming various object attributes, methods, and events. The attributes, methods, and events of an object are determined by the class to which the object belongs.
In Visual Basic. NET, various HTML server controls, Web server controls, and data controls are all objects. They not only have attributes and methods of common objects, but also have events. Events can be considered as responses of objects to messages of other objects. For example, the four TextBox controls used in example 3.8 all belong to the TextBox class. They all have attributes such as TextMode and TextBox, and events such as OnTextChanged.
Use the New statement in VB. NET to create an object.
Syntax:
Dim object name As Class Name
Object Name = New Class Name ()
The function of the preceding syntax is to create a class object. The process of creating an object is also called Instantiation. Note that the key word New must be used for object initialization. The New method is the constructor of the VB. NET class. Constructor is a special method. It must be used during class initialization. When an object is initialized with the New Keyword, the class constructor is called.
The preceding two statements can be simplified to one statement:
Dim object name As New class name ()
The following statement creates an Employee Class Object:
Dim Obj As Employee
Obj = New Employee ()
The preceding statement can be simplified:
Dim Obj As New Employee ()
Syntax:
Object Name. method name real parameter table)
Object Name. Domain Name
The preceding syntax is used to call object methods and reference object fields. For example, Obj. PrintSalray ().

BibliographyPrevious sectionNext section

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.