tailieunhanh - Mastering Microsoft Visual Basic 2010 phần 5

loại, có một tập hợp của các biến địa phương, như họ đang tuyên bố trong các mã lớp. Các thủ tục khác nhau của lớp được gọi là cần thiết bởi Common Language Runtime (CLR) và họ hành động trên các thiết lập của các biến địa phương tương ứng với trường hợp hiện tại của lớp. | 388 chapter 10 applied OBJECT-ORIENTED PROGRAMMING type there s a set of local variables as they re declared in the class code. The various procedures of the class are invoked as needed by the Common Language Runtime CLR and they act on the set of local variables that correspond to the current instance of the class. Some of the local variables may be common among all instances of a class These are the variables that correspond to shared properties properties that are being shared by all instances of a class . When you create a new variable of the Customer type the New procedure of the Customer class is invoked. The New procedure is known as the class constructor. Each class has a default constructor that accepts no arguments even if the class doesn t contain a New subroutine. This default constructor is invoked every time a statement similar to the following is executed Dim cust As New Customer You can overload the New procedure by specifying arguments and you should try to provide one or more parameterized constructors. Parameterized constructors allow you or any developer using your class to create meaningful instances of the class. Sure you can create a new Customer object with no data in it but a Customer object with a name and company makes more sense. The parameterized constructor initializes some of the most characteristic properties of the object. Objects versus Object Variables All variables that refer to objects are called object variables. The other type of variables are value variables which store base data types such as characters integers strings and dates. In declaring object variables we usually use the New keyword which is the only way to create a new object. If you omit this keyword from a declaration only a variable of the Customer type will be created but no instance of the Customer class will be created in memory and the variable won t point to an actual object. The following statement declares a variable of the Customer type but doesn t create

TỪ KHÓA LIÊN QUAN