Skip to content
← Back to Community
How to access one class from another class that's in the same project
Profile icon
NimishP

I want to make a project that consists of different games in different classes. How would I do this?

Here is the link to my repl
https://repl.it/@NimishP/Games

I want to be able to go from one class to another when I run the code.

Thanks,
NimishP

Voters
Profile icon
AndreaCompton
Profile icon
PinkyChandra
Profile icon
subhanshuja
Profile icon
amyb2022
Profile icon
benjaminviljoen
Profile icon
AllAwesome497
Profile icon
NimishP
Comments
hotnewtop
Profile icon
CARLOS-ALFRED13

you need use import classname: but the class that you want to import needs be "public"

Profile icon
TheDrone7

If the file with the class is in the same directory as your main file then you can simply do import ClassName; in your main.java file to start using it.

Profile icon
NimishP

@TheDrone7
Oh ok thanks!

Profile icon
NimishP

@TheDrone7
But it still doesn't work

Profile icon
TheDrone7

@NimishP
I see in your repl, you named all classes Main, that might be what's causing problem, also you import using class name not file name, and I don't see any imports in your main Java file in the repl.

Profile icon
ShivamArora1

@NimishP

It doesn't work

Profile icon
AllAwesome497

Make annother class with everyone in it?

Profile icon
NimishP

@AllAwesome497
What do you mean by that?

Profile icon
AllAwesome497

@NimishP
like make a new class then put every student in that one, I'm not familiar with the classroom stuff on repl, but can't students be in more than one class? Edit: like each one is in the class for all ur classes and they're period specific ones.

Profile icon
AllAwesome497

Oof read that wrong. Couldn't u copy the code?