I am implementing Java 8 interface default method as follows,
**
package com.company;
interface defualtdemo
{
default void print(){
System.out.println("Print 1");
}
}
interface defualtdemo1
{
default void print(){
System.out.println("Print 2");
}
}
abstract class demo{
public void print()
{
System.out.println("Abstract Print");
}
}
public class Main extends demo implements defualtdemo,defualtdemo1 {
// public void print(){
// System.out.println("Main Print");
// }
interface MathOpertion{
public int opertion(int a,int b);
}
public static void main(String[] args) {
new Main().print();
MathOpertion add=(int a,int b)->{return a+b;};
MathOpertion sub=(int a,int b)->{return a-b;};
System.out.println(add.opertion(10,5));
System.out.println(sub.opertion(10,5));
}
}
**
Even not implementing a default method "Print" still showing output like follows,
Abstract Print 15 5
My question is why java compiler not showing EXCEPTION FOR NOT IMPLEMENTING "Print" METHOD IN MAIN CLASS?.
Comments
Post a Comment