Which is the Best Java Web Framework ?

Java 8 - Default Methods - Base Class Method Definition has precedence over Interface Default Method definition

Base Class Definition has precedence over Interface Default Method if both are being extended and implemented and have common method definition.

Sample Code and Output 

HelloJava8Base 

public class HelloJava8Base {
     public void defaultMethod() {
         System.out.println("Default Method Base Class Implementation");
     }
}

DefaultMethodInterface 

public interface DefaultMethodInterface {
     default public void defaultMethod() {
         System.out.println("Default Method Interface Implementation");
     }
}

HelloJava8

public class HelloJava8 extends HelloJava8Base implements DefaultMethodInterface,DefaultMethodInterface2 {
   public static void main(String[] args){
       DefaultMethodInterface dmi = new HelloJava8();
       dmi.defaultMethod(); // Prints "Default Method Base Class Implementation"
    }
}
Subscribe to Java News and Posts. Get latest updates and posts on Java from Buggybread.com
Enter your email address:
Delivered by FeedBurner
comments powered by Disqus




×

Try our new Java Interview Questions Search Tool.

There are more than 1000 questions with practice tests.

It's updated daily and It's Awesome.


×

Try our new Java Practice Test tool.

There are more than 200 questions and expanding quickly. It's updated daily and It's Awesome.