Thursday 21 January 2016

Java Tutorial : Java method overriding(default method super)


Click here to watch in Youtube :
https://www.youtube.com/watch?v=eWR06PEiyFY&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Java method overriding(default method super) 
InterfaceA.java
public interface InterfaceA
{
    default public void sayWelcome()
    {
        System.out.println("Welcome by InterfaceA");
    }
}
InterfaceB.java
public interface InterfaceB
{
    default public void sayWelcome()
    {
        System.out.println("Welcome by InterfaceB");
    }
}
MyClass.java
public class MyClass implements InterfaceA, InterfaceB
{
    public void sayWelcome()
    {
        System.out.println("Welcome by MyClass,Calling "
                + "super interfaces default methods");
        InterfaceA.super.sayWelcome();
        InterfaceB.super.sayWelcome();
    }
}
MethodOverrideTest.java
public class MethodOverrideTest
{
    public static void main(String[] args)
    {
        MyClass myClassObj = new MyClass();
        myClassObj.sayWelcome();            
    }

}
Output
Welcome by MyClass,Calling super interfaces default methods
Welcome by InterfaceA
Welcome by InterfaceB
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/MethodOverridingDemo-defaultmethod-super-App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/MethodOverridingDemo-defaultmethod-super-App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/fa67e02bcd9efeae1c2ea3019677c5252e4db5f7/BasicJava/MethodOverridingDemo-defaultmethod-super-App/?at=master

See also:
  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment