> For the complete documentation index, see [llms.txt](https://hanfak.gitbook.io/workspace/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://hanfak.gitbook.io/workspace/languages/java/intermediate/oop/interfaces.md).

# Interfaces

* [Interfaces](/workspace/languages/java/intermediate/oop/interfaces.md#interfaces)
  * [What?](/workspace/languages/java/intermediate/oop/interfaces.md#what)
  * [Why use?](/workspace/languages/java/intermediate/oop/interfaces.md#why-use)
  * [Override method](/workspace/languages/java/intermediate/oop/interfaces.md#override-method)
  * [Inheritence](/workspace/languages/java/intermediate/oop/interfaces.md#inheritence)
  * [Default Methods (JAVA8 +)](/workspace/languages/java/intermediate/oop/interfaces.md#default-methods-java8-)
  * [other](/workspace/languages/java/intermediate/oop/interfaces.md#other)
  * [Links](/workspace/languages/java/intermediate/oop/interfaces.md#links)

## What?

* is an abstract type that is used to specify a behavior that classes must implement.
  * Is just a contract. The implementing class ensures, that it will have these methods that can be used on it. It is basically a contract or a promise the class has to make.
  * A class can implement multiple interfaces
* A Java interface is a bit like a class, except a Java interface can only contain method signatures and fields. An Java interface cannot contain an implementation of the methods, only the signature (name, parameters and exceptions) of the method.
* Interfaces cannot be instantiated (does not container constructor), but rather are implemented. A class that implements an interface must implement all of the non-default methods described in the interface, or be an abstract class.
* Object references in Java may be specified to be of an interface type; in each case, they must either be null, or be bound to an object that implements the interface.
* Interfaces can extend multiple interfaces
* <https://www.quora.com/If-asked-on-a-coding-interview-What-is-the-primary-difference-between-an-interface-and-abstract-class-what-is-the-correct-answer>

## Why use?

* Interfaces are the best way to maintain well decoupled constructs.
* You can use interfaces in Java as a way to achieve polymorphism.

## Override method

* annotation
  * Use of @Override above method declaration, to say it is using the method from the interface
* Why?
  * <https://stackoverflow.com/questions/94361/when-do-you-use-javas-override-annotation-and-why>
  * <https://javarevisited.blogspot.com/2012/11/why-use-override-annotation-in-java.html>

## Inheritence

* inherit from interfaces
  * classes
  * interfaces
* multiple inheritence

## Default Methods (JAVA8 +)

* Issues
  * Multiple inheritence

## other

* methods
* Reference types
  * polymorphism
  * cannot use concrete implementation class which has its own method with this ref type

## Links


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://hanfak.gitbook.io/workspace/languages/java/intermediate/oop/interfaces.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
