• 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

Interfaces

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are interfaces implicitly static ?
class x{
interface y{}
class m{
interface l{}
}
}
While compiling this code,i am getting a message saying that interface l is implicitly static.but no error for interface y.
what is the meaning of static when applied to classes and interfaces?
for the matter ,what is the meaning of final when applied to innner classes?
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Iterfaces are implicitly abstract. In your example, you're declaring an interface inside a class.
Static modifier can be applied to instance variables and methods. These variables and methods belong to the class and not the instance of the class. So, if that class (with static members in it), is instantiated many many times, the static variable is shared by all the instances. They share only one copy.
Static modifier when applied to interface? Interface methods cannot be static, only public and abstract. Interface variables are declared public, static and final.
Hope this helps
[ August 07, 2003: Message edited by: sherry cuenco ]
 
Eric Lidell
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
But why does the compiler show error for interface l and not for y?
class x{
interface y{}
class m{
interface l{}
}
}
if i replace the same code as follows
class x{
interface y{}
static class m{
interface l{}
}
}
it works fine.
Whats the reason?
why is an interface within a nested class implicitly static ?
any reason why?
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Simon,

In the above example interface y and interface I are member interfaces .
and member interfaces are always implicitly static so they are never considered to be inner classes.
And an inner class can never refer to static members (i.e non-final members)
So inner class m cannot refer to interface I

But in ur second example ..

class m is static nested class that can access static members and hence can access interface I.
for details refer to :
http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#270924

Regards,
Cody
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch "Cody" and thanks for paticipating in this forum. Please take a few moments to review JavaRanch's Naming Policy and change your displayed name accordingly. Thanks - Barry(Moderator)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic