Results 1 to 8 of 8
  1. #1
    dragonchr15 is offline Member
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Default Question about packages.

    Hi everyone.

    I'm studying for the Sun Certified Java Programmer exam, and I have a question about packages. I'm playing around to get the gist of things, and I created a package called human_being and I placed one file in the directory, an abstract class called Human. It compiles fine.

    Then, I made a CONCRETE class called Man.java that extends from Human.java, and implemented all of the abstract methods as per the rules. When I compile Man.java, I get:

    Java Code:
    Man.java:3: cannot find symbol
    symbol: class Human
    class Man extends Human {
    Followed by a whole slew of errors saying that symbols can't be recognized, clearly the result of the error above. Is there some rule against having a superclass and subclass in the same package? When I created a separate test class in the human_being package that didn't extend from Human, it worked fine.

    Am I missing something?

    Thanks.

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    did you put them in the same package? what code did you have?

  3. #3
    dragonchr15 is offline Member
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Default Code...

    Both files are in the same package and the same directory. The code for Human.java:

    Java Code:
    package human_being;
    
    enum Race { WHITE,LATINO_HISPANIC,ASIAN,BLACK_AFRICAN,NATIVE_AMERICAN,MIDDLE_EASTERN }
    enum Religion { CHRISTIAN,JUDAISM,HINDUISM,ISLAM,BUDDHISM,ATHEIST }
    enum HairColor { PLATINUM_BLONDE,DIRTY_BLONDE,BRUNETTE,BLACK,RED }
    
    public abstract class Human {
    
    	protected int age;
    	protected int weight;
    	protected int height;
    	protected String name;
    	protected Race race;
    	protected Religion religion;
    	protected HairColor hairColor;
    	protected String occupation;
    	
    	public abstract void eatFood(String food);
    	public abstract void useFacilities(String waste);
    	public abstract void laugh();
    	public abstract void cry();
    	public abstract void outputCharacteristics();
    	public abstract void setJob(String newJob);
    }
    Code for Man.java:

    Java Code:
    package human_being;
    
    public class Man extends Human {
    	
    	public Man(int age, int weight, int height, String name, Race race, Religion religion, HairColor hairColor) {
    		this.age = age;
    		this.weight = weight;
    		this.height = height;
    		this.name = name;
    		this.race = race;
    		this.religion = religion;
    		this.hairColor = hairColor;
    	}
    	
    	public void eatFood(String food) {
    		System.out.println("Mmmm...that " + food + " sure taste good!");
    	}
    	
    	public void useFacilities(String waste) {
    		System.out.println(name + " just " + waste);
    	}
    	
    	public void laugh() {
    		System.out.println(name + " finds that joke funny.");
    	}
    	
    	public void cry() {
    		System.out.println(name + " is very sad.");
    	}
    	
    	public void outputCharacteristics() {
    		System.out.println("Name: " + name);
    		System.out.println("Age: " + age);
    		System.out.println("Weight: " + weight);
    		System.out.println("Height: " + height + " inches");
    		System.out.println("Race: " + race);
    		System.out.println("Religion: " + religion);
    		System.out.println("Hair Color: " + hairColor);
    		System.out.println("Occupation " + occupation);
    	}
    	
    	public void setJob(String newJob) {
    		occupation = newJob;
    	}
    I'm just playing around...:)

  4. #4
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    i'm pretty sure your problem is in your Human class. try putting the enums inside the class declaration and see what happens

  5. #5
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    actually i just tried compiling your code and it worked fine for me...

  6. #6
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    might seem stupid, but did you name your directory correctly?

  7. #7
    dragonchr15 is offline Member
    Join Date
    Aug 2009
    Posts
    4
    Rep Power
    0

    Default

    You put both files in a directory called human_being and included "package human_being at the top, right? It actually compiled fine when I removed the package statement for some reason.

    For me, the Human.java file compiles fine, but I get over 25 errors when I try to compile Man.java.

    I have a the human_being directory in my src folder, and all my class output go to the bin. For example (I'm using a Mac):

    /src/human_being

    All class files go into:

    /bin/human_being

  8. #8
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    how are you compiling it? you need to be in the root directory relative to the packages i believe, which is the directory above human_being

Similar Threads

  1. Packages
    By urbim in forum Eclipse
    Replies: 2
    Last Post: 07-02-2009, 03:01 PM
  2. packages
    By fogus in forum New To Java
    Replies: 1
    Last Post: 03-24-2009, 07:14 AM
  3. Replies: 3
    Last Post: 02-12-2008, 12:03 PM
  4. Using packages
    By prfalco in forum New To Java
    Replies: 5
    Last Post: 01-31-2008, 11:38 PM
  5. packages
    By ai_2007 in forum Advanced Java
    Replies: 1
    Last Post: 07-31-2007, 01:10 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •