• Post Reply Bookmark Topic Watch Topic
  • New Topic

Problem in understanding package  RSS feed

 
hariharan thiruvottriyur
Greenhorn
Posts: 4
C++ Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello everyone

I'm stuck in understanding package access

I have create a user defined package named inheritance.This package act as a container for my classes Animal.java,Dog.java,and animaldriver classes.

Animal.java source code here


Dog.java


Now i'm compile the Animal.java without an error but when i'm compiling Dog.java the compiler report an error that
Dog.java:3: error: cannot find symbol
public class Dog extends Animal {
^
symbol: class Animal
Dog.java:17: error: cannot find symbol
System.out.println(name + "barking");
^
symbol: variable name
location: class Dog
2 errors
Why this happen please help me to solve this problem Thank you.
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, and thanks for using code tags!

The classes as you've posted them seem to be fine. Did you compile from the command line? What folder/directory were you in when you compiled? What was the exact command you used to compile?
 
hariharan thiruvottriyur
Greenhorn
Posts: 4
C++ Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Knute Snortum Thanks for replying

I have created the inheritance folder and put these classes (Animal.java, Dog.java,animaldriver.java) into inheritance folder.I have set the current working directory to inheritance folder and start compiling the java files.I'm compiled the Animal.java file by using javac Animal.java command on the terminal, it compiles successfully without an error and create the Animal.class file in the inheritance folder.After that when i compiled Dog.java file the compiler report an error.I'm try to debug this problem by giving public access modifier to all the member of the class But problem still occur..

Screenshot-from-2015-06-13-19-21-04.png
[Thumbnail for Screenshot-from-2015-06-13-19-21-04.png]
inheritance folder
Screenshot-from-2015-06-13-19-23-15.png
[Thumbnail for Screenshot-from-2015-06-13-19-23-15.png]
terminal
 
Knute Snortum
Sheriff
Posts: 4288
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ah, I see. You have to call javac from the top of the package structure, in your case, ~/Desktop, so that javac knows where to look for Animal.java.

 
hariharan thiruvottriyur
Greenhorn
Posts: 4
C++ Java Java ME
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It works... thanks.

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!