Yahoo Answers is shutting down on May 4th, 2021 (Eastern Time) and the Yahoo Answers website is now in read-only mode. There will be no changes to other Yahoo properties or services, or your Yahoo account. You can find more information about the Yahoo Answers shutdown and how to download your data on this help page.
Trending News
Java Coding Help. Thanks!!?
I put this code into a Java Compiler and it gave me an error. I want to know how to fix the error.
Code:
import static java.lang.System.;
public class StarsAndStripes
{
public StarsAndStripes()
{
outprintln("StarsandStripes");
printTwoBlankLines();
}
public void printTwentyStars()
{
}
public void printTwentyDashes()
{
}
public void printTwoBlankLines()
{
}
public void printASmallBox()
{
}
public void printABigBox()
{
}
}
The error given was:
StarsAndStripes.java:1: error: <identifier> expected
import static java.lang.System.;
^
1 error
Java Coding Help. Thanks!! The question mark was typed on accident. Sorry.
1 Answer
- husoskiLv 72 years agoFavorite Answer
You need either a member name (which static field or method) on that static import statement, or a * to import all of them. Either of these will compile:
import static java.lang.System.out; // can shorten calls to out.println(...) after this
import static java.lang.System.*; // import all public static names--usually a bad idea
The * is really an "import on demand" declaration. The compiler will look in the named class only for names that aren't either defined in your source code, or explicitly imported from somewhere.
Static imports should be used very rarely; and the on-demand version even less often if at all. I can't remember the last time I used either of those forms. As Guido Van Rossum (inventor of Python) has often said, programs are read more often than they are written. It's generally a bad idea to make the meaning of a program less clear (by hiding which class a symbol is defined in) just to save some typing time.