Pergunta de entrevista da empresa Infosys

"They asked me to explain the difference between an abstract class and an interface in Java, and when I would use one over the other."

Resposta da entrevista

Sigiloso

15 de mai. de 2025

An abstract class can have both abstract and concrete methods, and it's used when classes share a common base with default functionality. Interfaces, on the other hand, are used when I want to enforce a contract without dictating how it's implemented. I’d use an abstract class when I have a base class with shared logic, and an interface when I want multiple classes to follow the same method signature but with different implementations."