Câu hỏi phỏng vấn Java
Câu hỏi

Does Java support multiple inheritance?

Câu trả lời

Java does not support multiple inheritance through classes due to the complexity and potential issues it introduces, such as the diamond problem. In Java, a class can only inherit from one superclass. However, Java provides a way to achieve similar functionality through the use of interfaces. A class in Java can implement multiple interfaces, which allows it to inherit abstract methods from multiple sources[1][2][3][4][5][6][7][8].

Multiple inheritance in programming languages like C++ allows a class to inherit from more than one class, which can lead to ambiguity if the multiple superclasses have methods with the same signature. This is known as the diamond problem, where the compiler cannot determine which superclass method to use. Java avoids this issue by disallowing class-based multiple inheritance[1][2][3][6].

Instead, Java uses interfaces to achieve multiple inheritance of type. Interfaces only declare methods but do not implement them, except in the case of default methods introduced in Java 8. Even with default methods, if a ...

middle

middle

Gợi ý câu hỏi phỏng vấn

senior

How do you find out what client machine is making a request to your servlet?

middle

Explain different ways of creating a thread. Which one would you prefer and why?

senior

Explain the available thread states in a high-level.

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào