Inheritance (again)

I have a class (ClassA) which has a property (Name) with scope Protected. I create another class (ClassB) which inherits from ClassA.
The sacred texts say that a class inherits all public and protected properties and methods from the super class, but my ClassB does not see the Protected property of the super class.
Am I doing something wrong?
Thank you all.

I don’t know where you read that, but for a Class, the property can only be accessed within that specific class and is not available to subclasses. The rules are slightly different for Modules. Perhaps you should use Private scope.

Thank you, Tim.
From Xojo documentation:


A scope of protected means the item is accessible from the current class instance (or the class itself for shared items) and its subclasses.

A Protected method, property, or constant is available only to other code within the class and subclasses based on the class.

It seems that the subclass inherits only the public properties/methods, but not the protected ones. So I don’t know what is the meaning of protected…

The old documentation indicates otherwise.

I’m sorry, but testing indicates I was confused myself. Protected is in fact available to subclasses. Private is not.

1 Like

Ok, that is what I have read and I knew for a while. But this is not true in facts: only public properties/methods are available to the subclass, not the protected ones.

I don’t have the latest version to test on, but on an older version, it works. Are you positive you have the Super set on the subclass? (First mistake I made while testing.)

I tried with Xojo 2019r1.1 and Xojo 2022.r2, but the things are the same: the subclass can only use the public properties/methods of its superclass.

I only have Xojo 2015r2.4 installed on this machine. It works here. The subclass can access Public and Protected properties, but it cannot access Private properties.

Perhaps my test is not correct: I have this code in the Opening event of a window:

Var clB As New ClassB

clB.      ' here I can see only the public properties/methods of ClassB

Don’t rely on autocomplete. That’s always been problematic. Just type in the property name and try to run the project.

Ok, found my mistake.
In the window Opening event I can’t see the protected properties, because I am outside the class, but in a method of Classb I can see also the protected ones.


Great. I’ve learned something new myself.

The protected properties/methods of the superclass are visible to all the subclasses, but only within the subclasses, not within a window

1 Like

Ah, good point. I was testing from within the subclass. Trying to access it from the window, I get a compile error:

“This property is protected. It can only be used from within its class.”