• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

class within interface and interface within class

 
Yi Meng
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For these two cases, are there any implicit modifiers applied to the declaration(i.e. an interface member variable is implicitly "public static final")?
Thanks in advance.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Member interfaces declared in a class are always implicitly static. JLS 8.5.2
Member classes and interfaces declared in an interface are always implicitly static and public. JLS 9.5
 
Rajinder Yadav
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
take a look at this posting if you read and understand the basics here, it will help you with your question.
But basically you can declare a class within an interface, since an interface is defined as 'static abstract', what this mean is that a classes declared within the interface will be treated as a top level nested class.
here is a sample code to show how to declared a class bar inside an interface foo and then use it.
just make sure you understand the difference between a class and an interface, and that you understand inner classes and nest classes, this will clear up the question for you.... read the previous posting and look at the java sun tutorial s it explains the diff between an interface and class

NOTE:
class bar1 is declared with a defult access modifier
class bar2 had a public access modifier
class bar3 is an abstract class which is extended by class foobar3
notice how class scoping is used to extend class foobar3
[ May 15, 2003: Message edited by: Rajinder Yadav ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic