research 2 code snippets
Snippet 1:
interface Int1{
String str = "123";
}
class Pparent{
String str = "123";
}
class F extends Pparent implements Int1{
}
this code compiles normally.
snippet2
class Pparent{
String str = "123";
public static String str = "123";
}
result: compile error with message
variable str is already defined in class
Resolution
for me both snippets looks like same.
Why does I see different results
update for Abimaran Kugathasan
you say:
Fields in interface are implicitly public static, and there not inherited to sub class
contr-example:
interface Int1{
String str = "123";
}
class F implements Int1{
public static void main(String[] args) {
System.out.println(F.str);
}
}
I cannot write so
class F extends Pparent implements Int1{
public static void main(String[] args) {
System.out.println(str);
}
}
why? I work with static content only.
They're clearly not the same. In your second snippet, you've got two variable declarations for the same name in the same class. That's a violation of this part of section 8.3 of the JLS:
In the first snippet, you're declaring one (implicitly static field in the interface and one field in the class. That doesn't violate any rules. Instead, it just follows this rule, also in section 8.3: