As others said, no, that’s really impossible, and your example could be solved by changing your model.
As an alternative to inheritance, you can use another class to transfer the Car instance.
I would make a Car interface (although working with RegisteredCar extend Car should also work), and then try to do something like the following pseudocode:
class RegisteredCar<T extends Car> implements Car { private final T car RegisteredCar(T car) { this.car = car; } ... methods for RegisteredCar ... methods from Car delegating to `this.car` }
Please excuse some bad code, I do not have an open IDE, and I always use generics without using an IDE.
Another possible solution is to use AOP, although I don’t know how it is in fashion, which these days, but what you are describing may be a problem with cross-references.
The ultimate alternative could be to use a language that allows the use of extensions, traits, protocol, or some other type of "mix in"
Gavin source share