aspose file tools*
The moose likes Beginning Java and the fly likes Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Interfaces " Watch "Interfaces " New topic
Author

Interfaces

Eric Lidell
Greenhorn

Joined: Jul 02, 2003
Posts: 20
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?
sherry cuenco
Greenhorn

Joined: May 07, 2003
Posts: 24
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

Joined: Jul 02, 2003
Posts: 20
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?
Cody Beth
Greenhorn

Joined: May 20, 2002
Posts: 11
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
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
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)


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Interfaces
 
Similar Threads
variable definitions within an interface
Variable scope within an interface and some questions
Nested Interface and static ...
interface for nested classes
class within interface and interface within class