Update index.md (#26358)

* Update index.md

Added statements to visualize interfaces differently.

* Formatting changes
This commit is contained in:
Raymart Evangelista
2018-12-26 15:26:34 -08:00
committed by Manish Giri
parent 0e86226911
commit f9f816514c

View File

@ -3,7 +3,11 @@ title: Interfaces
--- ---
# 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 ```java
public interface Vehicle { public interface Vehicle {
@ -46,7 +50,7 @@ Vehicle tesla = new Car();
tesla.start(); // starting engine ... 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! What can you do with this feature? Polymorphism! You can use only interfaces to refer to object instances!