What is "Override"?

About Monkey 2 Forums General Programming Discussion What is "Override"?

This topic contains 5 replies, has 4 voices, and was last updated by  abakobo 1 year ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
  • #8533


    I see this quite a lot in sample code (in method declarations), but it isn’t mentioned anywhere in the documentation.

    What does it mean?



    ‘Override’ replaces a ‘Virtual’ method by a new method.

    Class X has a virtual method doSomething().
    Class Y inherits/extends class X.
    Class Y would like to change the method doSomething(),
    so it overrides it. When calling Y.doSomething(),
    the overriden/replaced method is executed.

    Without the keyword ‘Override’ you could replace a
    method by accident, just by using the same method
    fingerprint (method name + parameters).
    To avoid such accidents, you have to explicitely
    use ‘Override’ to make sure it is really what you want
    to do.

    Search for “OOP override”: https://en.wikipedia.org/wiki/Method_overriding


    Mark Sibly

    Ugh, docs don’t even mention methods – will fix NOW!

    But as Danilo says, it’s basically indicates you’re ‘changing’ the behaviour of a method in a super class (which is usually declared ‘Virtual’, indicating it can be overridden).

    This is actually the default behavior in blitzmax/monkey, where all methods are virtual/override by default. In monkey2 you must explictly declare which methods can be overriden by subclass methods (with ‘Virtual’), and which methods are overriding superclass methods (with ‘Override’).



    Ok that makes sense.  Thanks for the info.


    As an aside, is there any documentation I can read to familiarise myself with monkey2, without asking a ton of noob questions?


    Mark Sibly

    There’s just the ‘docs’ and what’s here in the forums. But don’t be afraid to ask noob Qs, they’re usually quick and easy to answer and will help others out.



    I started to work on the docs to add some missing think. There’s a keyword index where you would have had a brief answer to the question. It is in total WIP but contains all the official infos + some I added.


    note that you can call the super method in you override with the Super keyword so you don’t have to rewrite all the super methods code.


    there’s also the Pakz exmples that are great to start with https://github.com/Pakz001/Monkey2examples

Viewing 6 posts - 1 through 6 (of 6 total)

You must be logged in to reply to this topic.