{"id":4864,"date":"2014-01-27T15:57:21","date_gmt":"2014-01-27T07:57:21","guid":{"rendered":"http:\/\/www.vbtutor.net\/?page_id=4864"},"modified":"2018-06-24T16:56:55","modified_gmt":"2018-06-24T08:56:55","slug":"visual-basic-2013-lesson-24-object-oriented-programming","status":"publish","type":"page","link":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-24-object-oriented-programming\/","title":{"rendered":"Visual Basic 2013 Lesson 24: Object Oriented Programming"},"content":{"rendered":"<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-23-creating-web-browser\/\">[Lesson 23] <\/a>&lt;&lt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-tutorial\/\">[Contents]<\/a> &gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-25-working-graphics\/\">[Lesson 25]<\/a><\/h4>\n<h3>24.1 The concept of Object-Oriented Programming<\/h3>\n<p>In this lesson, you will learn the basic concept of object-oriented programming. In order for a programming language to qualify as an object-oriented programming language, it must have three core technologies namely <strong>encapsulation, inheritance <\/strong>and<strong> polymorphism<\/strong>. These three terms are explained below:<\/p>\n<h4><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><br \/>\n<strong>24.1.1 Encapsulation<\/strong><\/h4>\n<p>Encapsulation refers to the creation of self-contained modules that bind processing functions to the data. These user-defined data types are called classes. Each class contains data as well as a set of methods which manipulate the data. The data components of a class are called instance variables and one instance of a class is an object. For example, in a library system, a class could be a member, and John and Sharon could be two instances (two objects) of the library class.<\/p>\n<h4><strong>24.1.2 Inheritance<\/strong><\/h4>\n<p>Classes are created according to hierarchies, and inheritance allows the structure and methods in one class to be passed down the hierarchy. That means less programming is required when adding functions to complex systems. If a step is added at the bottom of a hierarchy, then only the processing and data associated with that unique step needs to be added. Everything else about that step is inherited.<\/p>\n<h4><strong>24.1.3 Polymorphism<\/strong><\/h4>\n<p>Object-oriented programming allows procedures about objects to be created whose exact type is not known until runtime. For example, a screen cursor may change its shape from an arrow to a line depending on the program mode. The routine to move the cursor on the screen in response to mouse movement would be written for \u201ccursor,\u201d and polymorphism allows that cursor to take on whatever shape is required at runtime. It also allows new shapes to be easily integrated.Visual Basic 2013 allows users to write programs that break down into modules. These modules represent the real-world objects and are knows as classes or types.<\/p>\n<p>An object can be created out of a class and it is known as an instance of the class. A class can also comprise subclass. For example, the apple tree is a subclass of the plant class and the apple in your backyard is an instance of the apple tree class. Another example is student class is a subclass of the human class while your son John is an instance of the student class.<br \/>\n<script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h3>24.2 Some Examples<\/h3>\n<p>A class consists of data members as well as methods. In Visual Basic 2013, the program structure to define a Human class can be written as follows:<\/p>\n<pre style=\"font-size: 110%;\">Public Class Human\r\n'Data Members\r\nPrivate Name As String\r\nPrivate Birthdate As String\r\nPrivate Gender As String\r\nPrivate Age As Integer\r\n'Methods\r\n\r\nOverridable Sub ShowInfo( )\r\n MessageBox.Show(Name)\r\n MessageBox.Show(Birthdate)\r\n MessageBox.Show(Gender)\r\n MessageBox.Show(Age)\r\n\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>Another Example:<\/p>\n<pre style=\"font-size: 110%;\">Public Class Car\r\n'Data Members\r\nPrivate Brand As String\r\nPrivate Model As String\r\nPrivate Year Made As String\r\nPrivate Capacity As Integer\r\n\r\n'Methods\r\n\r\nOverridable Sub ShowInfo( )\r\n MessageBox.Show(Brand)\r\n MessageBox.Show(Model)\r\n MessageBox.Show(Year Made)\r\n MessageBox.Show(Capacity)\r\n\r\nEnd Sub\r\nEnd Class\r\n<\/pre>\n<p>Let\u2019s look at one example of how to create a class. The following example shows you how to create a class that can calculate your BMI (Body Mass Index).<\/p>\n<p style=\"text-align: left;\">To create a class, start Visual Basic 2013 as usual and choose Windows Applications. In the Visual Basic 2013 IDE, click on Project on the menu bar and select Add Class, the Add New Item dialog appears, as shown in Figure 24.1<a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4869\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg\" alt=\"vb2013_figure24.1\" width=\"955\" height=\"614\" \/><\/a><strong>Figure 24.1<\/strong><\/p>\n<p>The default class Class1.vb will appear as a new tab in a code window. Rename the class as MyClass.vb. Rename the form as MyFirstClass.vb.<\/p>\n<p>Now, in the MyClass.vb window, create a new class MyClass1 and enter the following code<\/p>\n<pre style=\"font-size: 110%;\">Public Class MyClass1\r\nPublic Function BMI(ByVal height As Single, ByVal weight As Single)\r\n BMI = Format((weight) \/ (height ^ 2), \"0.00\")\r\nEnd Function\r\nEnd Class\r\n<\/pre>\n<p>Now you have created a class (an object) called MyClass1 with a method known as BMI.<\/p>\n<p>In order to use the BMI class, \u00a0insert a button into the form and click on the button to enter the following code:<\/p>\n<pre style=\"font-size: 110%;\">Private Sub BtnBMI_Click(sender As Object, e As EventArgs) Handles BtnBMI.Click\r\nDim MyObject As Object\r\nDim h, w As Single\r\n MyObject = New MyClass1()\r\n h = InputBox(\"What is your height in meter\")\r\n w = InputBox(\"What is your weight in kg\")\r\n MessageBox.Show(MyObject.BMI(h, w))\r\nEnd Sub\r\n<\/pre>\n<p>When you run this program and click the button, the user will be presented with two input boxes to enter his or her height and weight\u00a0subsequently and the value of BMI will be shown in a pop-up message box, as shown in the figures below:<\/p>\n<p><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.2.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4871\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.2.jpg\" alt=\"vb2013_figure24.2\" width=\"369\" height=\"159\" \/><\/a><\/p>\n<p style=\"text-align: center;\"><strong>Figure 24.2\u00a0<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.3.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4872\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.3.jpg\" alt=\"vb2013_figure24.3\" width=\"369\" height=\"159\" \/><\/a><strong>Figure 24.3<\/strong><\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.4.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-4873\" src=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.4.jpg\" alt=\"vb2013_figure24.4\" width=\"160\" height=\"155\" \/><\/a><strong>Figure 24.4<\/strong><\/p>\n<p><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js\"><\/script><br \/>\n<ins class=\"adsbygoogle\" style=\"display: block; text-align: center;\" data-ad-layout=\"in-article\" data-ad-format=\"fluid\" data-ad-client=\"ca-pub-3033628290023372\" data-ad-slot=\"3914691604\"><\/ins><br \/>\n<script>\n     (adsbygoogle = window.adsbygoogle || []).push({});\n<\/script><\/p>\n<h4 style=\"text-align: center;\"><a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-23-creating-web-browser\/\">[Lesson 23]\u00a0<\/a>&lt;&lt;\u00a0<a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-tutorial\/\">[Contents]<\/a>\u00a0&gt;&gt; <a href=\"http:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-25-working-graphics\/\">[Lesson 25]<\/a><\/h4>\n<p style=\"text-align: center;\">\n","protected":false},"excerpt":{"rendered":"<p>[Lesson 23] &lt;&lt; [Contents] &gt;&gt; [Lesson 25] 24.1 The concept of Object-Oriented Programming In this lesson, you will learn the basic concept of object-oriented programming. In order for a programming language to qualify as an object-oriented programming language, it must have three core technologies namely encapsulation, inheritance and polymorphism. These three terms are explained below: &hellip; <a href=\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-24-object-oriented-programming\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Visual Basic 2013 Lesson 24: Object Oriented Programming<\/span><\/a><\/p>\n","protected":false},"author":23013,"featured_media":0,"parent":0,"menu_order":0,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-4864","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.0 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Visual Basic 2013 Lesson 24: Object Oriented Programming - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB<\/title>\n<meta name=\"description\" content=\"This article discuss the concepts of object oriented programming in visual basic 2013\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Visual Basic 2013 Lesson 24: Object Oriented Programming - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"og:description\" content=\"This article discuss the concepts of object oriented programming in visual basic 2013\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html\" \/>\n<meta property=\"og:site_name\" content=\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Vbtutor\" \/>\n<meta property=\"article:modified_time\" content=\"2018-06-24T08:56:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:site\" content=\"@liewvk\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-24-object-oriented-programming\/\",\"url\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html\",\"name\":\"Visual Basic 2013 Lesson 24: Object Oriented Programming - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"isPartOf\":{\"@id\":\"https:\/\/www.vbtutor.net\/#website\"},\"primaryImageOfPage\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#primaryimage\"},\"image\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#primaryimage\"},\"thumbnailUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg\",\"datePublished\":\"2014-01-27T07:57:21+00:00\",\"dateModified\":\"2018-06-24T08:56:55+00:00\",\"description\":\"This article discuss the concepts of object oriented programming in visual basic 2013\",\"breadcrumb\":{\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#primaryimage\",\"url\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg\",\"contentUrl\":\"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg\",\"width\":955,\"height\":614},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/www.vbtutor.net\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Visual Basic 2013 Lesson 24: Object Oriented Programming\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.vbtutor.net\/#website\",\"url\":\"https:\/\/www.vbtutor.net\/\",\"name\":\"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB\",\"description\":\"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.\",\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Visual Basic 2013 Lesson 24: Object Oriented Programming - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"This article discuss the concepts of object oriented programming in visual basic 2013","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html","og_locale":"en_US","og_type":"article","og_title":"Visual Basic 2013 Lesson 24: Object Oriented Programming - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","og_description":"This article discuss the concepts of object oriented programming in visual basic 2013","og_url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html","og_site_name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","article_publisher":"https:\/\/www.facebook.com\/Vbtutor","article_modified_time":"2018-06-24T08:56:55+00:00","og_image":[{"url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg","type":"","width":"","height":""}],"twitter_card":"summary_large_image","twitter_site":"@liewvk","twitter_misc":{"Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.vbtutor.net\/index.php\/visual-basic-2013-lesson-24-object-oriented-programming\/","url":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html","name":"Visual Basic 2013 Lesson 24: Object Oriented Programming - Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","isPartOf":{"@id":"https:\/\/www.vbtutor.net\/#website"},"primaryImageOfPage":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#primaryimage"},"image":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#primaryimage"},"thumbnailUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg","datePublished":"2014-01-27T07:57:21+00:00","dateModified":"2018-06-24T08:56:55+00:00","description":"This article discuss the concepts of object oriented programming in visual basic 2013","breadcrumb":{"@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#primaryimage","url":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg","contentUrl":"https:\/\/www.vbtutor.net\/wordpress\/wp-content\/uploads\/2014\/01\/vb2013_figure24.1.jpg","width":955,"height":614},{"@type":"BreadcrumbList","@id":"http:\/\/www.vbtutor.net\/vb2013\/vb2013_lesson24.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.vbtutor.net\/"},{"@type":"ListItem","position":2,"name":"Visual Basic 2013 Lesson 24: Object Oriented Programming"}]},{"@type":"WebSite","@id":"https:\/\/www.vbtutor.net\/#website","url":"https:\/\/www.vbtutor.net\/","name":"Learn Visual Basic Programming \u2013 VB.NET, VBA &amp; Classic VB","description":"Start learning Visual Basic from beginner to advanced. Includes VB.NET, VBA, and classic VB tutorials for students and professionals.","inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4864","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/users\/23013"}],"replies":[{"embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/comments?post=4864"}],"version-history":[{"count":41,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4864\/revisions"}],"predecessor-version":[{"id":13078,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/pages\/4864\/revisions\/13078"}],"wp:attachment":[{"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/media?parent=4864"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/categories?post=4864"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.vbtutor.net\/index.php\/wp-json\/wp\/v2\/tags?post=4864"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}