1

Is it possible to set an object as a class that isn't its own class?

For instance, if I have a class of Class_Fruit and a class of Class_Apple, is there any way to do:

Dim appleClass as Class_Fruit
Set appleClass = New Class_Apple

Like what you can do in other languages like Java

I suspect it's not possible, because VBA is just not built to work like that and it doesn't have inheritance, but I wanted to ask to make sure.

I've had a look around but not been able to find a definitive answer, so I figured I should ask before I waste any more time trying to get it to work. I'm RELATIVELY new to Class objects in VBA, and pretty much all I can find about them is how to build them, not the further levels of functionality that they might have.

I have a workaround I can use if this isn't possible, but doing this would be much easier if there is any way to do it at all.

GSerg
  • 76,472
  • 17
  • 159
  • 346
  • 1
    So if your `Class_Fruit` is an interface and your `Class_Apple` has `Implements Class_Fruit`, then you can write code exactly as you've shown. – GSerg Jul 25 '19 at 14:17
  • Ah! Fantastic, thank you! Apologies if this is a duplicate of another question someone asked, I did look but I couldn't find anything – Jacknoshima Jul 25 '19 at 19:03

0 Answers0