How does composition differ from inheritance in OOP?
- Composition allows access to all methods of the composed class, whereas inheritance restricts access to superclass methods.
- Composition involves creating new classes from existing ones, whereas inheritance involves creating objects by combining other objects.
- Composition involves creating objects by combining other objects, whereas inheritance involves creating new classes from existing ones.
- Composition restricts access to all methods of the composed class, whereas inheritance allows access to superclass methods.
Composition and inheritance are two ways to establish relationships between classes in OOP. Composition involves creating complex objects by combining simpler ones, allowing for greater flexibility and reusability. Inheritance, on the other hand, allows a class (subclass) to inherit properties and behavior from another class (superclass).
Loading...
Related Quiz
- How can you implement a stack using two queues?
- The ___________ scheduling algorithm selects the process with the shortest burst time.
- The ___________ design pattern is used to provide a unified interface to a set of interfaces in a subsystem.
- Which ACID property ensures that transactions maintain consistency in the database?
- What is the function of an inode in a Unix-like file system?