PRASHNIKAप्रश्निका
‹ Back to the paper

What is an interface? How is it different from a class?

Computer Science20172 marksShort answer

Answer

Answer

AI
An interface in Java is a reference type that contains only abstract method declarations (no method bodies) and constants (public static final fields). It specifies what a class must do, and any class that implements it (using the keyword implements) must define all its methods. Difference from a class: a class contains data members and complete method definitions and can be instantiated with new, whereas an interface has no instance variables, no method bodies and cannot be instantiated. A class can inherit from only one class (extends) but can implement many interfaces, so interfaces give a form of multiple inheritance.
Inheritance, Interfaces and Polymorphism

From ISC 2017 Computer Science Paper 1, question 2(a).