Which design principle is violated if a superclass is aware of its subclasses?
- Encapsulation
- Inheritance
- Polymorphism
- Abstraction
When a superclass is aware of its subclasses, it violates the principle of encapsulation. Encapsulation refers to the concept of bundling data and the methods that operate on that data into a single unit or class. In object-oriented programming, classes should not have direct knowledge of their subclasses to promote loose coupling and maintainability. Instead, subclasses should inherit behavior and attributes from the superclass without the superclass needing to know specific details about its subclasses. Violating this principle can lead to code that is less flexible and harder to maintain.
Loading...
Related Quiz
- The process of an object inheriting properties and behaviors (methods) from its prototype is known as _________.
- JavaScript was introduced to the world in the year _________.
- How can one emulate the functionality of a switch statement using objects and functions in JavaScript?
- Which JavaScript method is used to bind a function to a specific object?
- The _______ keyword is used to define a constructor inside a class to create objects.