Yes, it is perfectly legal to assign a subclass object to a superclass reference in object-oriented programming. This is a fundamental principle of polymorphism, where a subclass instance can be treated as an instance of its superclass. However, when doing so, you may lose access to the specific methods and properties of the subclass unless you cast it back to the subclass type. This allows for more flexible code but requires careful management to avoid runtime errors.
Copyright © 2026 eLLeNow.com All Rights Reserved.