File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inherting Static classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inherting Static classes" Watch "Inherting Static classes" New topic
Author

Inherting Static classes

Pal Sudarshan
Ranch Hand

Joined: Jun 10, 2004
Posts: 52
My first question is, Can we extend static classes?

My second question is from the code below, which is modified version of sample code from Prof. K's book.

The question is: When I compile the source code, I get the error
"modifier static not allowed here." Why is that?

static class Superclass
{static int x = 0;}

class TopLevelClass
{private int x = 1;
class Inner extends Superclass
{
public void print()
{
System.out.println(this.x);
}
}
}
public class Access
{ public static void main(String[] args)
{ TopLevelClass.Inner ref = new TopLevelClass().new Inner();
ref.print();
}
}
Baps Vakkalagadda
Ranch Hand

Joined: May 25, 2004
Posts: 47
I think you must be getting the static error for SuperClass. It is beacuse top level class is not allowed to have static modifier. Only inner classes can be static. Try the same code by keeping the SuperClass inside TopLevelClass.
Baps Vakkalagadda
Ranch Hand

Joined: May 25, 2004
Posts: 47
I think you must be getting the static error for SuperClass. It is beacuse any top level class is not allowed to have static modifier. Only inner classes can be static. Try the same code by keeping the SuperClass inside TopLevelClass.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inherting Static classes