interface variables are final and static by default and methods are public and abstract
Posted
by sap
on Stack Overflow
See other posts from Stack Overflow
or by sap
Published on 2010-04-14T08:08:47Z
Indexed on
2010/04/14
8:13 UTC
Read the original article
Hit count: 205
java
The question is why it's been decided to have variable as final and static and methods as public and abstract by default.
Is there any particular reason for making them implicit,variable as final and static and methods as public and abstract.
Why they are not allowing static method but allowing static variable?
We have interface to have feature of multiple inheritance in Java and to avoid diamond problem. But how it solves diamond problem,since it does not allow static methods.
In the following program, both interfaces have method with the same name..but while implementing only one we implement...is this how diamond problem is solved?
interface testInt{ int m = 0; void testMethod(); }
interface testInt1{ int m = 10; void testMethod(); }
public class interfaceCheck implements testInt, testInt1{
public void testMethod(){
System . out . println ( "m is"+ testInt.m );
System . out . println ( "Hi World!" );
}
}
© Stack Overflow or respective owner