GithubHelp home page GithubHelp logo

dezren39 / methodoverrideexample_vb.net Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 30 KB

I made this small project to demonstrate the keywords 'Override' and 'Overridable' for my peers.

Visual Basic 100.00%

methodoverrideexample_vb.net's Introduction

MethodOverrideExample_VB.NET

I made this small project to demonstrate the keywords 'Override' and 'Overridable' for my peers.

Public Class HowManyTires
    Class Auto
            Overridable Function Tires() As Decimal 'Allows derived classes to Override Tires()
                     Tires = 4 'Hard coding is bad, this is an example. Please forgive me.
            End Function
    End Class


    Class Moto
            Inherits Auto 'This means that the Moto Class inherits and becomes derived of Auto
            Overrides Function Tires() As Decimal 'Replace Auto's Tires() method with Moto's
                     Tires  = 2 'Hard code still bad,  a couple less though.
            End Function
    End Class


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Dim Automobile As Auto = New Auto 'Make a new instance of the class Auto
            Dim Motorcycle As New Moto 'Make a new instance of the derived class Moto

            lblAuto.Text = "An automobile has this many tires: " + Automobile.Tires().ToString 
            lblMoto.Text = "A motorcycle has this many tires: " + Motorcycle.Tires().ToString

            'Both text labels above receive their values from the same method call. One
            'instance generates from Auto as 4, the other generates from Moto as 2. 
            'This was achieved through allowing the base class's function to be Overridable 
            'and Override'ing the base function.
    End Sub
End Class

methodoverrideexample_vb.net's People

Contributors

dezren39 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.