method type in Interface Class in java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

method type in Interface Class in java

Hi all i got error for method type in "default" , "private" and "protected" for this method is only type , public?? my Inerface: interface Parent { final int i = 0; default void showmsg(); }

1st Nov 2020, 11:19 AM
Hadi
Hadi - avatar
2 Answers
+ 3
Interface is reference type like classes. It's only contains Constants, method signature, defult method. Interface variable and method are public static final by default. So other modifiers are not allowed, that's why you get those error. Interface method are abstract , but from java 8 interface method are allowed not to be abstract. (default methods) If you having trouble with defult methods than probably you are using older java version.
1st Nov 2020, 11:42 AM
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~
0_O-[Mägár_Sám_Äkà_Nüllpøïntêr_Èxëcéptïön]~~ - avatar
+ 1
ok my java version: java version "1.8.0_112" my error : missing method body or declare abstract!!
1st Nov 2020, 12:01 PM
Hadi
Hadi - avatar