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
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).]
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.