Java: Interfaces

Photo by Killian Cartignies on Unsplash

What is a reference type?

Reference data types in Java are those which contain references to the address of dynamically created objects. class types, arrays types, interface types.

Abstract methods in interfaces

Figure 1.1: Comparable Interface
Figure 1.2: Implementing the Comparable Interface

Implementing interfaces

  1. You have to declare that your class intends to implement an interface via the implements followed by the interface name. Example:

Constants in interfaces

Using interface as a type

Figure 2.1: Using an interface as a data type
Figure 2.2: Interface as parameter type and return type

Why use interfaces?

  • Multiple inheritance
  • Organizational benefits
  • Loose coupling potential

Common interview questions on Interfaces




Computer Science Student, Programming Enthusiast

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Tips for Managing Technical Translations

8 Interesting AWS Services

Say Hello to 1Blocker X

Data & Procedure Stacks

Moving Machine Image from one project to another project as VM

ZS_F (Soybean): Forecasting The Path Higher

What happens when you type gcc main.c?

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anton Suprun

Anton Suprun

Computer Science Student, Programming Enthusiast

More from Medium

Coding with Java Optionals.

Java Polymorphism in 3mins

The Evolution Of Switch Statement From Java 7 to Java 17

Functional Programming In Java