‹ Back to the paper
Question 2(a)
2 marks
Computer ScienceISC 2017 Computer Science Paper 1Short answerInheritance, Interfaces and Polymorphism
Answer the following question.
What is an interface? How is it different from a class?
Answer
Answer
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.