Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Interfaces

Lesson 25 of 39 in the free Java notes on Siksha Sarovar, written by Rohit Jangra.

Interface

A component used to achieve 100% Abstraction and Multiple Inheritance. • Syntax: interface InterfaceName { ... } • Compiled to a .class file.

Members of Interface

MemberClassInterface
VariablesYesPublic, Static, Final (Constants)
MethodsYesPublic, Abstract (Default)
ConstructorsYesNo
Static MethodsYesYes (From JDK 1.8)
Default MethodsNoYes (From JDK 1.8)

Notes: • All members are implicitly public. • Variables must be initialized (since they are final). • Cannot create an object of Interface.

Inheritance

  1. Class implements Interface: class C implements I1
  2. Interface extends Interface: interface I2 extends I1
  3. Multiple Inheritance:
  4. • Class can implement multiple interfaces: class C implements I1, I2 • Interface can extend multiple interfaces: interface I3 extends I1, I2

Diamond Problem Solved: Interfaces have no constructors and no state (instance variables). Ambiguity in method calls is resolved because implementation is forced in the concrete child class.

Types of Interfaces

  1. Regular Interface: More than one abstract method.
  2. Functional Interface: Exactly one abstract method. (e.g., Runnable, Comparable).
  • Used in Lambda Expressions.
  1. Marker Interface: No methods. Empty.
  • Tells JVM about certain activity. (e.g., Serializable, Cloneable, RandomAccess).