Skip to content
Sign upLog in
← Back to Community

How to add classes in Java?

Profile icon
[deleted]

I have kept the Main class, but when i try to change the name I get a error. Also, if i try to add classes (And I keep the Main class) I get a error stating that I have a duplicate class, however, I do not have two classes called by the same name. I have tried googling the problem but all examples of the problem are to hard for me to understand as i have just started out with Java.

Answered by paulfears [earned 5 cycles]
View Answer
Voters
Profile icon
RabiRath
Profile icon
ThanusanRamanas
Profile icon
NaveenPNair
Profile icon
KevinCarias
Profile icon
Shadowgarden
Profile icon
ESTHERUZOZIE
Profile icon
CupOfTem
Profile icon
NatalieDawnshad
Profile icon
MiaHeyward
Profile icon
naen2019
Comments
hotnewtop
Profile icon
paulfears

you can add a class in java by creating a separate java file and with the class you want to import in it. Then simply call the class it does not require the import function.
Here is an example:
https://repl.it/@paulfears/import-custom-class-java

Profile icon
hayaodeh

hmmmm I don't know how to add classes in Java either 😞 but maybe other replers can help out. are you with us on our discord server?

Profile icon
AvoBolivar

How do you add another java file?

Profile icon
BlueDraconix

@AvoBolivar
when adding a new file, have ".java" after the file name.

Profile icon
[deleted]

Thanks! I understand now how to add classes. Earlier I was a bit confused about the files, but I understand them now.