Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

problem with accessing classes in the same package with package access

807601Dec 15 2007 — edited Dec 16 2007
I 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?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 13 2008
Added on Dec 15 2007
23 comments
1,208 views