| Author |
why interface variables are static and final. what is reason to declare them as like that?
|
ranjithkumar.gendhe kumar
Greenhorn
Joined: Oct 12, 2010
Posts: 19
|
|
|
why interface variables are static and final. what is reason to declare them as like that?
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
They are implicitly static and final because instance variables don't work with polymorphism. They can be used to allow implementing classes to have access to the same set of constants.
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Muhammad Khojaye
Ranch Hand
Joined: Apr 12, 2009
Posts: 341
|
|
|
http://www.coderanch.com/t/178630/java-SCJA/certification/Instance-variables-interface
|
http://muhammadkhojaye.blogspot.com/
|
 |
Arun Giridharan
Ranch Hand
Joined: Sep 30, 2010
Posts: 290
|
|
|
Interface came into picture to solve the problem of Diamond shape problem.If you know what is static and final keywords that's you have the answer.
|
 |
ranjithkumar.gendhe kumar
Greenhorn
Joined: Oct 12, 2010
Posts: 19
|
|
how interface solve the diamond shape problem
i declared like this
interface i1{
int a=12;
}
interface i2{
int a=21;
}
class exampleInterface implements i1,i2{
public static void main(String...a){
System.out.println(a);// it is compilation error
}
}
please clarify this one
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
Arun Giridharan wrote:Interface came into picture to solve the problem of Diamond shape problem.If you know what is static and final keywords that's you have the answer.
Interface where introduced to allow programming to an interface and not an implementation. This allows you to decouple the implementation and the interface.
And kumar please UseCodeTags.
|
 |
ranjithkumar.gendhe kumar
Greenhorn
Joined: Oct 12, 2010
Posts: 19
|
|
thank you.
interface can contain class.
in which cases this will be useful explain with an example.
|
 |
Arun Giridharan
Ranch Hand
Joined: Sep 30, 2010
Posts: 290
|
|
ranjithkumar.gendhe kumar wrote:how interface solve the diamond shape problem
i declared like this
please clarify this one
First it's not a instance variable,so please give a value.
see the following code
|
 |
ranjithkumar.gendhe kumar
Greenhorn
Joined: Oct 12, 2010
Posts: 19
|
|
|
ok i gave values to it.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32838
|
|
|
Careful about spellings: what does "k" mean? I it "OK" spelt incorrectly?
|
 |
ranjithkumar.gendhe kumar
Greenhorn
Joined: Oct 12, 2010
Posts: 19
|
|
|
ok. i corrected.
|
 |
 |
|
|
subject: why interface variables are static and final. what is reason to declare them as like that?
|
|
|