So I got a compile error, who doesn't find the class Person (it works fine if I remove to use the packages)

How can I make javac find Person.class?

package mypackage;

 public class Person {
     private String name;

 public Person(){
   this("Papadopoulos");
  }

 public Person(String name){
   setName(name);
  }

 public void setName(String name){
    this.name = name;
  }

 public String getName(){
    return( name );
  }

}

public class Student extends Person {
    private String am;
 private String department;

public Student(){
   this("0", "0", "0");
 }

public Student(String am, String department, String name){
   super(name);
   setAm(am);
   setDepartment( department );
}

public void setAm(String am){
   this.am = am;
  }

public String getAm(){
   return( am );
  }

public void setDepartment(String department){
   this.department = department;
  }

public String getDepartment(){
   return( department );
  }
}
有帮助吗?

解决方案

it works fine if I remove to use the packages

You need to Store this file inside mypackage folder.

Than go to command prompt

C:\pathTomyPackage>javac Person.java

NOTE: Use cd folderName command to go Inside folder upto .java file.

or

C:\>javac PathToFile\Person.java

其他提示

Assuming the two classes are in two different packages, you may want to import the class Person in the class Student.

Also check that Person and Student class in seperate files.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top