File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inherting Static classes

 
Pal Sudarshan
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 47
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic