0

Stupid question, I'm sure: For an assignment I need to create a program that uses methods and constructors in several other classes... the classes were in a file that I unpacked and put in the same directory as the one I'm writing is in. What do I need to do so that I can call other methods/constructors from those classes and get my program to compile without telling me it can't find them??

4
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by Ezzaral
0

If they aren't part of the same package then lets say you have a class called OtherClass in a package called other. Then you would need to add the following statement to the top of the class you wanted to use OtherClass from:

import other.OtherClass;

Then you would be able to do something like

//in some method:
OtherClass object = new OtherClass();
System.out.println(object.toString());

Edited by BestJewSinceJC: n/a

0

You'll also face problems importing those classes if they were compiled into packages and you have unpacked them into a different directory structure.

edit: Just to elaborate a bit, in the example BJSC posted above, the compiler would expect "OtherClass" to be found in a directory named "other".

Edited by Ezzaral: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.