homerun
homerun

Reputation: 20765

Does Implements works only with interfaces?

Learning a little-bit about java Interfaces and Implements made me question ,

  1. if Inheritance works only with classes does the Implements work only with Interfaces , or it may has another uses?

  2. Does java has to offer us "built-in" Interfaces that we can Implements into our program without creating it? and if so where i can find a list of those.

Upvotes: 0

Views: 401

Answers (2)

Makoto
Makoto

Reputation: 106470

if Inheritance works only with classes does the Implements work only with Interfaces , or it may has another uses?

Inheritance in general can apply to classes and interfaces through the use of the extends keyword. That is to say, a class can inherit properties and functions from another class, whereas an interface can expand its contractual obligations from another interface.

Example:

public interface Phone {
    String getNumber();
}

public interface MobilePhone extends Phone {
    public boolean isSmartPhone();
}

If one were to implement the MobilePhone interface above, they'd also have to implement the getNumber() method as well.

As for implements - that only works with interfaces.

Does java has to offer us "built-in" Interfaces that we can Implements into our program without creating it? and if so where i can find a list of those.

They're not "built-in" per se; they're prewritten for you in Java. The Java API is the best place to look for first-party interfaces; however, it's worth noting that you can get third-party interfaces from other packages and frameworks, such as Spring, Guice, and Guava, or from some other developer's JAR that you happen to include in your project.

Upvotes: 1

Dipen Adroja
Dipen Adroja

Reputation: 425

Only interfaces can be implemented.

JAVA have many builtin interface that you can implement based on your requirement.

More than that a class can implement only interface while it can extend more than one class

Upvotes: 0

Related Questions