Question

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 );
  }
}
Was it helpful?

Solution

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top