File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Basic Q Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Make it so: Java DB Connections & Transactions this week in the JDBC forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Basic Q" Watch "Basic Q" New topic

Basic Q


Joined: Jan 25, 2001
Posts: 26
What is wrong with the following code n why???
public class test
System.out.println("In test");
static void nnn()
static int i = 1;
public static void main(String args[])
test t = new test();
System.out.println("What is the problem");
2) Can be abstract methods be static n if no then why???
Lee Clarke

Joined: Jan 18, 2001
Posts: 18
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)
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).]

Lee Clarke - SCJP
natarajan meghanathan
Ranch Hand

Joined: Feb 01, 2001
Posts: 130
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.

Sun Certified Programmer for Java 2 Platform
I agree. Here's the link:
subject: Basic Q
It's not a secret anymore!