0

Can we call static member of interface using object creation

interface i1{ static void m1(){ System.out.println(" m1 in i1") } } Class A{ public static void main(String [] args){ A a1 = new A(); a1.m1(); } }

15th Apr 2020, 12:06 PM
Rajesh Deshbandhu
Rajesh Deshbandhu - avatar
2 ответов
0
No. You can't access by object. Static methods are class level, so you can access by derefferncing of class or interface name.. In the code a1.m1(); not works.. But i1.m1(); works...
15th Apr 2020, 1:24 PM
Jayakrishna 🇮🇳
0
I think no, just this interface i1 { static void m1() { System.out.println(" m1"); } default void m2() { System.out.println(" m2"); } } class A implements i1 { public static void main(String [] args){ A a1 = new A(); i1.m1(); // without create obj a1.m2(); // without static } }
15th Apr 2020, 1:32 PM
zemiak