#Importing an In or Out Class

31 messages · Page 1 of 1 (latest)

weary estuary
#

I was given an In and Out class and so I put it in the same place as my java file to create my project, but I don't know how to import and use the class properly as it seems. The Internet just offers similar programs with the scanner class, but how is it for custom classes?

gentle kindleBOT
#

This post has been reserved for your question.

Hey @weary estuary! Please use /close or the Close Post button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

upper marlin
#

you import classes based on their package name

weary estuary
#

package name?

upper marlin
#

if you'd have the class ```java
package a.b.c;

public class D { /* code here... */ }
, you would do java
import a.b.c.D;

// ...
D somethingWithD = new D();
// ...
// ...

#

you don't have packages anywhere, and since both the class you want to use and the class you want to use it from are in the same package (the default one), you don't need to add any imports

#

that's a special case, if both classes are in the same package, you dont need to import it

#

so to answer simply, you dont need to add any imports, you just do Out.something(), Out out = new Out(...);, or whatever you want to do with the Out class

weary estuary
#

ooooh

upper marlin
#

same with In

weary estuary
#

but it still returns me the same problem about not being able to resolve the Out in the Out.println(x2); part

gentle kindleBOT
upper marlin
weary estuary
upper marlin
#

oh wait i see, the files are classes

#

that should work then

#

what's the code you're working with now

weary estuary
#
public class Hello {

    /**
     * @param args
     */
    public static void main(String[] args) {
        String x2 = "Hello World";
        Out.println(x2);
    }


}```
upper marlin
#

is that all of it

weary estuary
#

yes

upper marlin
#

try to run ```ps
& 'C:\Program Files\Java\jdk-21\bin\java.exe' -cp 'D:\Users\Your Username\New folder' Hello

weary estuary
#

It returns Hello World

upper marlin
#

seems to work when you manually do it

#

i think the issue is that vscode is just bad kekw

weary estuary
#

eeeeeeeh

#

Could it maybe also be because I saved the data on the D-drive and java and vs code is located on C?

weary estuary
#

okay it also works after I copied the whole project onto C and did the usual javac

#

wait both works what is dis magic

#

thanks you btw!

gentle kindleBOT
# weary estuary thanks you btw!

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.