Click here to watch in Youtube :
https://www.youtube.com/watch?v=IRg4HW4P7x8&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Java method overriding(Instance method preference) |
public interface InterfaceA { default public void sayWelcome() { System.out.println("Welcome by InterfaceA"); } }
public class Parent { public void sayWelcome() { System.out.println("Welcome by Parent Class"); } }
public class MyClass extends Parent implements InterfaceA { }
public class MethodOverrideTest { public static void main(String[] args) { MyClass myClassObj = new MyClass(); /* * Default methods and abstract methods in interfaces are inherited like * instance methods. * * Instance methods are preferred over interface default methods. */ myClassObj.sayWelcome(); } }
Welcome by Parent Class
https://sites.google.com/site/javaee4321/java/MethodOverridingDemo-perference-App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/MethodOverridingDemo-perference-App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/fa67e02bcd9efeae1c2ea3019677c5252e4db5f7/BasicJava/MethodOverridingDemo-perference-App/?at=master
See also:
No comments:
Post a Comment