Prashnikaप्रश्निका
Code
About
‹ Back to the paper

Question 2(c)

2 marks

Computer ScienceISC 2020 Specimen Computer Science Paper 1Short answerInheritance, Interfaces and Polymorphism

Answer the following in short.

Define Interface. How is it different from a Class?

Answer

Answer

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