The problem has two simple programs that they put in the same directory:
1.
FileName:Test.java
Import Show;
public class Test {
public static void Main (string[] args) {
Show Sungo = new Show ();
Sungo.myname ();
}
}
2.
FileName:Show.java
public class show{
public void MyName () {
System.out.println ("My name is helloworld!");
}
}
After compiling the Show.java, compile Test.java and the following error prompts appear
----------Javac----------
Test.java:3: '. ' Expected
Import Show;
^
1 Error
-------------------------------
In the Test.java file
Import Show; After the comment is dropped, it will compile through, execute the Java test.class,
----------Java----------
My name is helloworld!
Java compile-time search classpath. ".;" is already set in Classpath, which is the current directory. The editor automatically looks for the class contained in the current directory and joins the import show if it is present; it was superfluous to think that there would be no problem, nor did you see a book stating that there was a problem. Through the above test, found not to do is not to do, useless. The problem was found in an example of a so-called authoritative book, and it was not known whether the author of the book had a test or if he was using a JDK version of another planet.
A simple example of another package and import
Create a new dir folder and put Show.java into the folder to compile.
FileName:Test.java
Import dir. Show;
public class Test {
public static void Main (string[] args) {
Show Sungo = new Show ();
Sungo.myname ();
}
}
FileName:Show.java
Package dir; The new section
public class show{
public void MyName () {
System.out.println ("My name is helloworld!");
}
}
Execution results
----------Java----------
My name is helloworld!
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service