You are not logged in.

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

1

Monday, September 27th 2010, 1:14pm

overriding method from superclass

Hello,

if I do this in Java:

Source code

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class Main {
    public static void main(String[] args) {
        BaseClass B = new BaseClass();
        B.Foo();
        System.out.println("");

        DrvdClass D = new DrvdClass();
        D.Foo();
        System.out.println("");

        B = D;
        B.Foo();
        System.out.println("");
    }
}
class BaseClass {
    void Foo(){
        System.out.println( "BaseClass -> Foo" );
        FooOverridable();
    }
    void FooOverridable(){
        System.out.println( "BaseClass -> FooOverridable" );
    }
}
class DrvdClass extends BaseClass {
    @Override void FooOverridable(){
        System.out.println( "DrvdClass -> FooOverridable" );
    }
}

I get the following output:

Source code

1
2
3
4
5
6
7
8
BaseClass -> Foo
BaseClass -> FooOverridable
 
BaseClass -> Foo
DrvdClass -> FooOverridable
 
BaseClass -> Foo
DrvdClass -> FooOverridable


But if we try to do the same thing in Jabaco:

Jabaco Source

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
Public Sub Form_Load()
   
   Dim B As New BaseClass
   B.Foo
   Debug.Print vbCrLf
  
   Dim D As New DrvdClass
   D.Foo()
   Debug.Print vbCrLf
   
   B = D
   B.Foo()
   Debug.Print vbCrLf
   
End Sub


with the class BaseClass:

Jabaco Source

1
2
3
4
5
6
7
Public Sub Foo()
   Debug.Print "BaseClass -> Foo"
   FooOverridable()
End Sub
Public Sub FooOverridable() 'virtual    'Overridable
   Debug.Print "BaseClass -> FooOverridable"
End Sub


and the class DrvdClass that has BaseClass as the SuperClass
(just type BaseClass in property-Editor field (SuperClass))

Jabaco Source

1
2
3
Public Sub FooOverridable()
   Debug.Print "DrvdClass -> FooOverridable"
End Sub


we get the following output that is significantly different from the java output:

Source code

1
2
3
4
5
6
7
8
9
BaseClass -> Foo
BaseClass -> FooOverridable

 *** Load DrvdClass
BaseClass -> Foo
BaseClass -> FooOverridable

BaseClass -> Foo
BaseClass -> FooOverridable


I must guess that the method FooOverridable never gets overridden.

Is it true?



How to override a method from superclass in Jabaco?

is there a certain neverdetected keyword in Jabaco?

Other languages use the keywords:

VB.net: Overridable, Override

C++, C#, Delphi: virtual; overrides

java: @Override

maybe an additional keyword is not necessary because it is clear that a method with the same name must be overridden by the derived class.



many regards

OlimilO

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

2

Monday, September 27th 2010, 3:04pm

Hi,
after a bit of experimenting, I've found out what is missing in your sample.

The following code for BaseClass works as you expected:

Jabaco Source

1
2
3
4
5
6
7
8
Public Sub FooOverridable()
   Debug.Print "BaseClass -> FooOverridable"
End Sub

Public Sub Foo()
   Debug.Print "BaseClass -> Foo"
   Me.FooOverridable
End Sub


Note the difference?
I am calling "Me.FooOverridable" rather than just "FooOverridable".

Adding "Me." makes the call to refer to the instance method,
while leaving it out, you just call the class method.
All in all, this sample leaves some confusion behind ...

Cheers

A1880

OlimilO

Intermediate

  • "OlimilO" is male
  • "OlimilO" started this thread

Posts: 277

Date of registration: Jan 18th 2009

Location: Germany

Occupation: software engineer

  • Send private message

3

Monday, September 27th 2010, 6:08pm

Hi A1880,

Quoted

Note the difference?

Aahh, thanks a lot for testing around! :thumbup:

Quoted

Adding "Me." makes the call to refer to the instance method,

it works ... that's why I always had the dim feeling that It was working already before... ;)

Quoted

while leaving it out, you just call the class method.

what do you mean when you say: class method?

e.g. a class method in Delphi is a
static method in C++ and a
shared method in VB.net


kind regards

OlimilO

A1880

Intermediate

  • "A1880" is male

Posts: 500

Date of registration: Jan 1st 2009

Location: Hanover, Germany

Occupation: Software Engineer

Hobbies: Hilbert Curves

  • Send private message

4

Tuesday, September 28th 2010, 10:09am

Yes, with class method I mean the static method.
However, I am not sure what happens if you access member variables from such a method.
I have not experimentes with methods explicitly declared as "static".

Overriding probably needs some more testing, explanation and clarification.

"@Override" is not mandatory for Java. It just tells the compiler to check and compare the parameter signatures.
Using a decompiler I've found that Jabaco compiles the methods 1:1 without change.
Therefore, the overriding principles of Java should apply.

Greetings

A1880

Rate this thread
WoltLab Burning Board