Classes are types and Objects are instances of the Class. Classes and Objects are very much related to each other. Without objects you can't use a class. In Visual Basic we create a class with the Class statement and end it with End Class. The Syntax for a Class looks as follows:
Public Class Test
----- Variables
-----Methods
-----Properties
-----Events
End Class
The above syntax created a class named Test. To create a object for this class we use the new keyword and that looks like this: Dim obj as new Test(). The following code shows how to create a Class and access the class with an Object. Open a Console Application and place the following code in it.
Module Module1
Imports System.Console
Sub Main()
Dim obj As New Test()
'creating a object obj for Test class
obj.disp()
'calling the disp method using obj
Read()
End Sub
End Module
Public Class Test
'creating a class named Test
Sub disp()
'a method named disp in the class
Write("Welcome to OOP")
End Sub
End Class
Output of above code is the image below.
Fields, Properties, Methods and Events
Fields, Properties, Methods, and Events are members of the class. They can be declared as Public, Private, Protected, Friend or Protected Friend.
Fields and Properties represent information that an object contains. Fields of a class are like variables and they can be read or set directly. For example, if you have an object named House, you can store the numbers of rooms in it in a field named Rooms. It looks like this:
Public Class House
Public Rooms as Integer
End Class
Properties are retrieved and set like fields but are implemented using Property Get and Property Set procedures which provide more control on how values are set or returned.
Methods represent the object’s built-in procedures. For example, a Class named Country may have methods named Area and Population. You define methods by adding procedures, Sub routines or functions to your class. For example, implementation of the Area and Population methods discussed above might look like this
Public Class Country
Public Sub Area()
Write("--------")
End Sub
Public Sub population()
Write("---------")
End Sub
End Class
Events allow objects to perform actions whenever a specific occurrence takes place. For example when we click a button a click event occurs and we can handle that event in an event handler.
Popular Posts
-
Now I will show you how to retrieve the data posted from a HTML file in a JSP page. Consider an html page that prompts the user to enter his...
-
Accessing the Standard CGI Variables: To build the successful web application, you often need to know a lot about the environment in which ...
-
INTRODUCTION TO 'C': C is a programming language developed at AT & T's Bell laboratories of USA in 1972.it was designed by d...
-
SQL aliases can be used with database tables and with database table columns, depending on task you are performing. SQL column aliases are u...
-
Learning about Events (Continue) Lets program the Form_Load event. "MsgBox" is Visual Basic command that launch a message box. for...
-
Steps to follow: 1. Write Person.java as shown below in Code-11.3.a under polypackage directory. (You are welcome to do this work using eit...
-
The Command Button's KeyPress, KeyDown and KeyUp Events The events that will be mentioned in the following pages are commonly used, and ...
-
The SQL AVG aggregate function selects the average value for certain table column. Have a look at the SQL AVG syntax: SELECT AVG(Column1) FR...
-
package interfaceexercise; // Define an interface with three abstract methods. // Any class that implements this interface has to // impleme...
-
We will use the Customers table to illustrate the SQL LIKE clause usage: FirstName LastName Email DOB Phone John Smith John.Smith@yaho...
No comments:
Post a Comment