Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Basic Q

 
GK
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is wrong with the following code n why???
----------
public class test
{
test()
{
System.out.println("In test");
}
static void nnn()
{
static int i = 1;
}
public static void main(String args[])
{
test t = new test();
test.nnn();
System.out.println("What is the problem");
}
}
----------------
2) Can be abstract methods be static n if no then why???
Gunjan
 
Lee Clarke
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I believe your problem is that you can't have a static automatic(local) variable
static void nnn()
{
static int i = 1;
}
if you remove the static keyword it compiles fine.(note: local variables cant have access modifiers only thing that would work is the final keyword)
Lee
also static methods cant be abstract, if the were then you could not override them when creating a subclass!
[This message has been edited by Lee Clarke (edited February 02, 2001).]
[This message has been edited by Lee Clarke (edited February 02, 2001).]
 
natarajan meghanathan
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Abstract methods cannot be static, because static methods are the representatives of the class and cannot be overridden. So there is no point in allowing abstract static methods.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic