From f9f816514cc981fc78b5d2f0bb79d09d8ca2e11f Mon Sep 17 00:00:00 2001 From: Raymart Evangelista <44074441+revang10@users.noreply.github.com> Date: Wed, 26 Dec 2018 15:26:34 -0800 Subject: [PATCH] Update index.md (#26358) * Update index.md Added statements to visualize interfaces differently. * Formatting changes --- guide/english/java/interfaces/index.md | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/guide/english/java/interfaces/index.md b/guide/english/java/interfaces/index.md index bf55cff9ae6..3a226a6a8cc 100644 --- a/guide/english/java/interfaces/index.md +++ b/guide/english/java/interfaces/index.md @@ -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!