Back to the 2023 paper

Module III: Basics of Web Programming

20232m

What are interfaces in JAVA.

Worked SolutionAI Assisted

An interface in Java is a reference type that declares abstract methods (and constants) without providing a full implementation. A class that implements the interface must define all its methods.

interface Shape {
    double area();          // implicitly public abstract
}

class Circle implements Shape {
    double r;
    Circle(double r) { this.r = r; }
    public double area() { return Math.PI * r * r; }
}

Key points:

  • Achieves 100% abstraction (before Java 8) and supports multiple inheritance of type, since a class can implement many interfaces.
  • Since Java 8 an interface can also contain default and static methods.
  • Fields are implicitly public static final.

Similar questions

Official AppAndroid App

PYQDeck for Android

Solve BEU previous-year exam papers anywhere, anytime. Fast search, offline paper viewing, and step-by-step solutions designed specifically for your phone.