Tested it for curiosity... in fact, class inheritance is there, hidden in the Java translation of the project.
There is the #Extends keyword, which only appears as IDE's context help in Activities and Services, but if you add it to a class, magic (dirty magic) happens
Not sure if it's been left there to be useful in some cases, or simply "is there" and can be removed one day.
Assume your package name is com.myapp.b4a
This is our simple parent class
[CODE lang="b4x" title="parentClass.bas"]Sub Class_Globals
Public afield As Int
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize
afield = 10
Log("parent initialize")
End Sub
Public Sub sayhello
Do While True
Log("Hello "&afield)
afield = afield +1
Sleep(1000)
Loop
End Sub
[/CODE]
We define a childClass, in which, only by mentioning that it extends parentClass, can access it as own methods (except for initialization, which needs an inline Java workaround)
[CODE lang="b4x" title="childClass.bas"]
'Note it is all lower-case
#Extends: com.myapp.b4a.parentclass
Public Sub Initialize( container As Panel )
' Before anything else
Dim JO as JavaObject = Me
JO.RunMethod("initSuper", Null)
' ...
Log($"Parent's field is ${JO.GetField("_afield")}"$) '<- belongs to the parent's class
JO.RunMethod("_sayhello", Array(Me)) '<- calling method of the paren'ts class.
End Sub
#If JAVA
public void initSuper(){
try{
com.myapp.b4a.parentclass mySuper = (com.myapp.b4a.parentclass) this;
mySuper._initialize(this, ba);
}
catch(Exception e){
BA.Log("Oops! Could not init super class");
}
}
#End If
[/CODE]
Of course it is not practical at all (but interesting, at least for me), since parent's class fields/methods have no direct support from B4A code, but only via JavaObject / inline Java, as if they also belonged to (in fact they are part of) to the child class.
