[Gambas-user] More on overriding native classes

Benoît Minisini gambas at ...1...
Sun Jun 24 22:52:47 CEST 2012


Le 18/06/2012 15:29, Bruce a écrit :
> On Mon, 2012-06-18 at 22:39 +0930, Bruce wrote:
>
>> Try this:
>> Create a new command line project in the IDE.
>> Add a new class "Application" with the following contents
>>
>>          ' Gambas class file
>>
>>          Create Static
>>          Inherits Application
>>          Export
>>
>>          Static Public Hello As String = "Hello from South Australia"
>>
>> Save and reload the project.
>> In MMain.Main type the following:
>>
>>          ?appl[Enter].he
>>
>> ( see screenshot appended)
>> Now that, to me, looks like we have successfully overridden the
>> Application class, but look what happens when you run it.
>>
>
> Let me rephrase that (sometimes the keyboard is quicker than the mind.)
>
> Try this:
> Create a new command line project in the IDE.
> Add a new class "Application" with the following contents
>
>         ' Gambas class file
>
>         Create Static
>         Inherits Application
>
>         Static Public Hello As String = "Hello from South Australia"
>
> Save and reload the project.
> In MMain.Main type the following:
>
>         ?appl[Enter].he
>
> ( see new! screenshot appended)
> Now that, to me, looks like we have successfully overridden the
> Application class, but look what happens when you run it.
>
>
> What you should see is a very correct error message saying that Hello
> is an unknown method in Application.  That is because it hasn't been exported.
> But when I go back and export the class, then I get the Multiple Inheritance error.
>
> B
>

If you export a class with a name that already exists, it automatically 
implies inheritance with overriding.

So you have a "multiple inheritance" error by using the "Inherits" keyword.

-- 
Benoît Minisini






More information about the User mailing list