0

Is default keyword in default methods in Java an optional specifier ? If not , then what type of specifier is it ?

interface TestInterface 
{ 
    // abstract method 
    public void square(int a); 

    // default method 
    default void show() 
    { 
      System.out.println("Default Method Executed"); 
    } 
} 
Number945
  • 4,631
  • 8
  • 45
  • 83
  • 1
    It's not optional because if you remove it in this code it stops compiling... I don't think this has a specific name, it's just a modifier. – Dici Sep 14 '19 at 15:56
  • Far as whether it is strictly necessary probably depends on what classes implement the interface, and whether or not they offer their own implementation of that method. However, if an existing interface already has a default method defined, it could definitely cause problems and compilation issues. – KellyM Sep 14 '19 at 16:02
  • `However, if an existing interface already has a default method defined, it could definitely cause problems and compilation issues.` What do you mean? It's fine to override a default method – Dici Sep 14 '19 at 16:06
  • @Dici `I don't think this has a specific name, it's just a modifier.` is the answer I was expecting. The question that you marked this as duplicate is not valid as I know how to use default methods and their purpose. Just wanted to know if it is some kind of special modifier and if yes , what will it be. – Number945 Sep 14 '19 at 16:19

0 Answers0