| preferred AP College board partner for AP classes
AP Computer Science A/Unit 5: Writing Classes
Start Practice TestPractice Test
About Exam
easy Solved by 1 students
Object Composition in Java
< Prev
Next >

In an enterprise management system, what design principle does the relationship between the ‘Office’ and ‘Employee’ classes demonstrate?

public class Employee {
    private String name;
    
    public Employee(String name) {
         this.name = name;
    }
    
    public void work() {
         System.out.println(name + " is working.");
    }
}

public class Office {
    private Employee manager;
    
    public Office(Employee manager) {
         this.manager = manager;
    }
    
    public void startDay() {
         manager.work();
    }
}
A

Inheritance, as Office extends the functionalities of Employee.

B

Composition, since Office contains an Employee object as a manager.

C

Encapsulation, due to hiding the internal state of the Employee.

D

Polymorphism, because Office can handle multiple types of Employee objects uniformly.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Not enough data yet to show leaderboard.

No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: [email protected]|Privacy Policy