There is a rule that every member of interface is only and only public whether you define or not. So when we define the method of the interface in a class implementing the interface, we have to give it public access as child class can’t assign the weaker access to the methods.
As defined, every method present inside interface is always public and abstract whether we are declaring or not. Hence inside interface the following methods declarations are equal.
void methodOne(); public Void methodOne(); abstract Void methodOne(); public abstract Void methodOne();
public : To make this method available for every implementation class.
abstract : Implementation class is responsible to provide implementation.
Also, We can’t use the following modifiers for interface methods.
If we change fun() to anything other than public in class B, we get compiler error “attempting to assign weaker access privileges; was public”
This article is contributed by Twinkle Tyagi. If you like GeeksforGeeks and would like to contribute, you can also write an article and mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above
Attention reader! Don’t stop learning now. Get hold of all the important Java and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready.
- Java | BiFunction Interface methods - apply() and addThen()
- Static methods vs Instance methods in Java
- Java 8 | Consumer Interface in Java with Examples
- Java 8 | BiConsumer Interface in Java with Examples
- Java 8 | DoubleToIntFunction Interface in Java with Example
- Java 8 | IntToDoubleFunction Interface in Java with Examples
- Java 8 | DoubleToLongFunction Interface in Java with Examples
- Java.util.function.BiPredicate interface in Java with Examples
- Java.util.function.DoublePredicate interface in Java with Examples
- Java.util.function.LongPredicate interface in Java with Examples
- Java.util.function.IntPredicate interface in Java with Examples
- Comparator Interface in Java with Examples
- Nested Interface in Java
- Queue Interface In Java
- List Interface in Java with Examples
- SortedSet Interface in Java with Examples
- Map Interface in Java
- SortedMap Interface in Java with Examples
- NavigableMap Interface in Java with Example
- Deque interface in Java with Example
Improved By : gauravmoney26