0% found this document useful (0 votes)
0 views2 pages

Interfces in Java

An interface in Java is a contract that specifies methods a class must implement without providing the implementation itself. It promotes abstraction, supports multiple inheritance, and enables polymorphism. An example is the 'Animal' interface with a 'makeSound' method, which is implemented by the 'Dog' class to produce a sound.

Uploaded by

splusmm24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views2 pages

Interfces in Java

An interface in Java is a contract that specifies methods a class must implement without providing the implementation itself. It promotes abstraction, supports multiple inheritance, and enables polymorphism. An example is the 'Animal' interface with a 'makeSound' method, which is implemented by the 'Dog' class to produce a sound.

Uploaded by

splusmm24
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

interface in Java

- by utk

What is an Interface in Java?


An interface in Java is a contract that defines what a class must do, but not how it does
it.

Think of it as a blueprint:

• It declares methods but does not implement them (until Java 8).
• A class that implements an interface must provide concrete implementations for
all its abstract methods.

🔹 Why Use Interfaces?

Achieve abstraction
Support multiple inheritance (Java doesn't allow multiple class inheritance)
Promote loose coupling and better testability
Enable polymorphism (use different implementations interchangeably)

🔹 Basic Interface Example


java
CopyEdit
interface Animal {
void makeSound(); // abstract method
}

class Dog implements Animal {


public void makeSound() {
System.out.println("Woof!");
}
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy