Update index.md (#26358)
* Update index.md Added statements to visualize interfaces differently. * Formatting changespull/26376/head^2
parent
0e86226911
commit
f9f816514c
|
@ -3,7 +3,11 @@ title: Interfaces
|
|||
---
|
||||
# Interfaces
|
||||
|
||||
Interface in Java is a bit like the Class, but with a significant difference : an `interface` can _only_ have method signatures, fields and default methods. Since Java 8, you can also create [default methods](https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html). In the next block you can see an example of interface :
|
||||
Interface in Java is a bit like the Class, but with a significant difference : an `interface` can _only_ have method signatures, fields and default methods. Since Java 8, you can also create [default methods](https://docs.oracle.com/javase/tutorial/java/IandI/defaultmethods.html).
|
||||
|
||||
Classes that implement an interface are thought to be signing a contract and agreeing to perform the specific behaviors listed in the interface. If the classes that implement an interface do not implement all the methods of the interface, then such a class needs to be defined as `abstract`.
|
||||
|
||||
In the next block you can see an example of interface :
|
||||
|
||||
```java
|
||||
public interface Vehicle {
|
||||
|
@ -46,7 +50,7 @@ Vehicle tesla = new Car();
|
|||
tesla.start(); // starting engine ...
|
||||
```
|
||||
|
||||
An Interface **can not** contain a constructor methods,therefore,you **can not** create an instance of an Interface itself. You must create an instance of some class implementing an Interface to reference it. Think of interfaces as a blank contract form, or a template.
|
||||
An Interface **can not** contain a constructor methods,therefore,you **can not** create an instance of an Interface itself. You must create an instance of some class implementing an Interface to reference it. Think of interfaces as a blank contract form, or a template.
|
||||
|
||||
What can you do with this feature? Polymorphism! You can use only interfaces to refer to object instances!
|
||||
|
||||
|
|
Loading…
Reference in New Issue