problem with accessing classes in the same package with package access
807601Dec 15 2007 — edited Dec 16 2007I have two java files ClassRoom.java and Person.java
The code in ClassRoom.java is as follows:
package exam.operators;
import java.io.*;
import java.util.*;
public class ClassRoom
{
private Hashtable inTheRoom = new Hashtable();
public void enterroom(Person p)
{
inTheRoom.put(p.getName(), p);
}
public Person getParent(String name)
{
Object p = inTheRoom.get(name);
if( p instanceof Parent)
{
return (Parent)p;
}
else
{
return null;
}
}
}
The code in Person.java is as follows
package exam.operators;
import java.io.*;
import java.lang.*;
class Person
{
protected String name;
public Person(String Name)
{
this.name = Name;
}
String getName()
{
return name;
}
}
class Parent extends Person
{
public Parent(String Name)
{
super(Name);
}
}
If classes with package access are available anywhere in the same package then my code should compile but in reality what happens is only Peron.java class compiles and when I try to compile ClassRoom.java I get the following errors.
D:\sun\exam\operators>javac Person.java works!
D:\sun\exam\operators>javac ClassRoom.java
ClassRoom.java:8: cannot find symbol
symbol : class Person
location: class exam.operators.ClassRoom
public void enterroom(Person p)
^
ClassRoom.java:12: cannot find symbol
symbol : class Person
location: class exam.operators.ClassRoom
public Person getParent(String name)
^
ClassRoom.java:15: cannot find symbol
symbol : class Parent
location: class exam.operators.ClassRoom
if( p instanceof Parent)
^
ClassRoom.java:17: cannot find symbol
symbol : class Parent
location: class exam.operators.ClassRoom
return (Parent)p;
^
4 errors
Could anyone please help me with these errors?