Ask coding questions

← Back to all posts
How to add classes in Java?

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 (64) [earned 5 cycles]
View Answer
paulfears (64)

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:


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

hayaodeh (171)

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?