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.