📢 Too many exams? Don’t know which one suits you best? Book Your Free Expert 👉 call Now!


    Question

    What is the primary difference between an abstract class

    and an interface in Java regarding abstraction?
    A Abstract classes can have constructors, while interfaces cannot. Correct Answer Incorrect Answer
    B Abstract classes can achieve 100% abstraction, while interfaces can only achieve partial abstraction. Correct Answer Incorrect Answer
    C Interfaces can have concrete methods, while abstract classes cannot. Correct Answer Incorrect Answer
    D A class can implement multiple abstract classes but can only extend one interface. Correct Answer Incorrect Answer
    E Abstract classes are used for data hiding, while interfaces are for method signatures. Correct Answer Incorrect Answer

    Solution

    o Abstract classes are still classes; they can have constructors, instance variables (fields), and both abstract and concrete methods. They can also contain state. o Interfaces are contracts that define a set of methods that a class must implement. Before Java 8, interfaces could only have abstract methods (and public static final fields). Since Java 8, they can have default and static methods, and since Java 9, private methods. However, interfaces cannot have constructors or instance variables (non-static fields).

    Practice Next
    ask-question