• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

why interface variables are static and final. what is reason to declare them as like that?

 
ranjithkumar.gendhe kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why interface variables are static and final. what is reason to declare them as like that?
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you.


interface can contain class.

in which cases this will be useful explain with an example.
 
Arun Giridharan
Ranch Hand
Posts: 290
Debian Fedora Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok i gave values to it.
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Careful about spellings: what does "k" mean? I it "OK" spelt incorrectly?
 
ranjithkumar.gendhe kumar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ok. i corrected.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic