• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

A static class ?

 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i got a question like that :

1) interface Foo{
2) int k=0;
3) }
4) public class Test implements Foo{
5) public static void main(Stringargs[]){
6) int i;
7) Test test =new Test();
8) i=test.k;
9) i=Test.k;
10) i=Foo.k;
11) }
12) }
what is the result?
it seems that after implements the interface Foo .its possible to access the int k by class name,but why?
Dos class Test become static ?
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
All variables defined in an interface are implicitly public, static and final.
That is why the variable "k" can be accessed directly, through the class name and also through any instance of the class. Since it is final you cannot make any changes to it.
 
guo mark
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
3x
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic