File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes why interface variables are static and final. what is reason to declare them as like that? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why interface variables are static and final. what is reason to declare them as like that?" Watch "why interface variables are static and final. what is reason to declare them as like that?" New topic
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: 449

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: 36478
    
  16
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why interface variables are static and final. what is reason to declare them as like that?
 
Similar Threads
why a transient variable can be declared with static modifier??
Confusion Here.. static contexts.
Why can't declare a Static method in Interface?
Interface variables
Non-final member variables in interfaces