• 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:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

nested classes within Interface

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
The members of a interface are implicitly public static and final.
if i declare a class within a interface ,is it public static and final too.
this code compiles correctly.
interface iface{
class class1{}
class class2 extends class1{}
/* shouldnt class1 be final because in an interface all the members are public ,final and static*/
}
class k{
public static void main(String args[])
{
iface.class1 x=new iface.class1();
/*this implies that the nested class is static */

}
}
Pls reply asap.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are really three different meanings of "final": it means "can't be overridden" when applied to a method; "can't be reassigned" when applied to a field; and "can't be extended" when applied to a class. Only meaning #2 holds for the members of an interface -- if the methods were "final" in sense #1, then an interface wouldn't be much use, right? Similarly, nested classes in an interface can be extended.
 
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
So the nested class in an interface conforms to sense 2,cant be changed.
What does cant be changed mean when applied to a class?
will the members be final and methods be final???
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Simon Templar:
So the nested class in an interface conforms to sense 2,cant be changed.
What does cant be changed mean when applied to a class?
will the members be final and methods be final???


Only variables are final in an interface. Classes are static and coderanch.
 
Thomas Paul
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to intermediate because it isn't a beginner's topic.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic