mirror of
https://github.com/adambard/learnxinyminutes-docs.git
synced 2025-01-14 05:05:59 +00:00
java: In Java 8, interfaces can have default method. (#2337)
This commit is contained in:
parent
d81e9735c2
commit
34456d988c
@ -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;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user