ProgrammingModerateProduct-company placement · Java
A Department has Professors who continue to exist if the department is closed, while a House is made of Rooms that cannot exist without the house. These two relationships are, respectively:
- A. Composition and aggregation
- B. Inheritance and composition
- C. Aggregation and composition
- D. Association and inheritance
Correct answer: C. Aggregation and composition
Both are has-a relationships; in composition the part's lifetime is owned by the whole (rooms die with the house), while in aggregation the parts are shared and independent.
More OOP with C++ and Java questions
- What is printed? java // static methods of the main class: static void p(Object o) { System.out.print("O"); } static void p(String s) {…
- What is printed? java Map<String, Integer> m = new TreeMap<>(Map.of("a", 1, "b", 2)); for (Map.Entry<String, Integer> e : m.entrySet())…
- What is printed? java Map<String, Integer> m = new TreeMap<>(Map.of("a", 1, "b", 2, "c", 3)); m.keySet().remove("b")…
- Which statement about the protected modifier is true in Java but NOT in C++?
- What is printed? java // file a/P.java package a; public class P { void f() { System.out.print("P"); } // package-private public void…
- What is printed? java String r = Stream.of(3, 1, 3, 2).distinct().sorted() .map(String::valueOf).collect(Collectors.joining("-"))…