Java under the package inheritance in the compiler but the solution

Source: Internet
Author: User

Code from the Java Core Technology volume

The abstract is represented as follows:

Managertest.java

Package inheritance;

...

public class Managertest

{

}

stored in: Inheritance/managertest.java

Manager.java

Package inheritance;

...

public class Manager

{

}

stored in: Inheritance/manager.java

Employee.java

Package inheritance;

...

public class Employee

{

}

stored in: Inheritance/employee.java

Okay, now compile it.

Javac *.java

Symbol not found

What do you mean?

Which means these three classes are placed in a folder inheritance.

One next to one

But when you compile, you don't see each other.

Well, how do we fix it?

Programme one:

Three classes are still thrown together in the inheritance folder

Comment out the package inheritance at the beginning of the three classes for example://package inheritance;

Compile javac *.java again

Scenario Two:

The class that will need to run the main () function refers to the outside of the folder

This is Managertest.java .

Take my experiment as an example:

The path to my computer is

F:\java1\fivecptr\fivecptrone\Inheritance (three classes in this)

I put Managertest.java in the java1 folder.

F:\java1\fivecptr\fivecptrone\Inheritance (remaining 2 classes)

....... ↑----------.....

Managertest.java

Then modify the code as follows

Inheritance two-class package changed to:

Package fivecptr.fivecptrone.inheritance;

....... __________↑_____________

F:\java1\fivecptr\fivecptrone\inheritance

is to copy the path behind the Managertest.java class. Of course "\" replaced by "."

TIPS: path names can not have strange symbols such as: underline _, Arabic numerals 0,1 ... (So fivecptr--!) with egg-ache

Next:

JAVA1 inside the managertest.java inside

1) Comment out package//package inheritance;

2) Add import fivecptr.fivecptrone.inheritance at the beginning. *; (As above, add the wildcard character at the end *)

Next, set the class path

(under Win7)

Computer-(left) computer right-Properties-Advanced system settings-environment variables-System variables-NEW

Name: CLASSPATH;

Path: F:JAVA1;.; (That is, the Managertest.java that class is located in the folder JAVA1 before-including the java1-path to write up, you can add another.; (Period + semicolon, if the scenario does not work, it may be the problem here, it represents the search class in the current directory)

Are you sure

Re-open Console (black box--!) )

CD to Managertest.java under File path

Run:

Javac Managertest.java

This article is from the "Kivilin_it_start" blog, make sure to keep this source http://kivilin.blog.51cto.com/6914610/1629991

Compiler is not compiled under package inheritance in Java solution

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.