This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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 OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Basic Q" Watch "Basic Q" New topic
Author

Basic Q

GK
Greenhorn

Joined: Jan 25, 2001
Posts: 26
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

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


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: http://aspose.com/file-tools
 
subject: Basic Q