This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes C++ #include equivalent for Java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "C++ #include equivalent for Java " Watch "C++ #include equivalent for Java " New topic

C++ #include equivalent for Java

Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150

If Class A has Class B, what do I need to do so Class A knows about Class B. I tried doing a simple inheretance program where I output a text on it's constructor but I am having a compile error on new ParentClass(). I dont have the actual compile error with me but I think it's what I have explain about. I tried searching it online but I couldn't find anything useful. Can anyone point me to the right direction.

Thank you.

star chaser..
Henry Wong

Joined: Sep 28, 2004
Posts: 18509

Java doesn't have a concept of an include file, the compiler is smart enough to get the class details directly from the class files.

If the classB is in the same package as classA (or in the java.lang package), you don't have to do anything. The compiler will find it for you. Otherwise, you can specify the package of classB using the "import" statement.


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Gary Ba
Ranch Hand

Joined: Oct 23, 2009
Posts: 150

Thank you. I got it to work.
I agree. Here's the link:
subject: C++ #include equivalent for Java
Similar Threads
Need help in javax.mail package.......very urgent
mock exam problem
Getting a servlet file to compile