So the way i’ve been told to do things is you have your file and the file name is Classname.java and then the code is something like this:
class ClassName {
SOME METHODS
main {}
}
and then thats all.
I’d like to have two objects defined and used within the same .java file. (i don’t want to have to put the other class in a difernt file just because i’d like to send this to someone and i want to avoid hasstle of atatching multiple files to an email [the lazy do make good programers though if you think about it])
- is it possible to do this?
- do i have to do anything special and if so what?
- what are some mistakes i’m likely to make or that you have made in the past when doing this?
Yes, you can have two classes defined in the same file. You need to define one of them as public, and that same class has to match the name of the file. Example: