java: In Java 8, interfaces can have default method. (#2337)

This commit is contained in:
Jakukyo Friel 2016-08-22 06:06:57 +08:00 committed by ven
parent d81e9735c2
commit 34456d988c

View File

@ -585,10 +585,14 @@ public interface Edible {
public interface Digestible { public interface Digestible {
public void digest(); public void digest();
// In Java 8, interfaces can have default method.
// public void digest() {
// System.out.println("digesting ...");
// }
} }
// We can now create a class that implements both of these interfaces. // We can now create a class that implements both of these interfaces.
public class Fruit implements Edible, Digestible { public class Fruit implements Edible, Digestible {
@Override @Override
public void eat() { public void eat() {
// ... // ...
@ -636,7 +640,7 @@ public abstract class Animal
// Method can have a body // Method can have a body
public void eat() public void eat()
{ {
System.out.println("I am an animal and I am Eating."); System.out.println("I am an animal and I am Eating.");
// Note: We can access private variable here. // Note: We can access private variable here.
age = 30; age = 30;
} }