Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: What is composition in OOP?
Answer: Composition is a way of creating complex objects by combining simpler objects or classes. It involves creating relationships between objects rather than relying on inheritance.

Example:

class Engine { 
/* Engine properties and methods */ 


class Car { 
private $engine; 
public function __construct(Engine $engine) { 
$this->engine = $engine; 

}
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook