Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple classes in single file

Tags:

java

oop

I'm having trouble putting multiple classes into a single file. For example, when my file looks like:

public class FirstClass() {}
public class SecondClass() {}
public class ThirdClass() {}

I get an error during compilation. I'm not quite sure what's causing this. Any ideas?

like image 251
Zach Latta Avatar asked Oct 30 '12 04:10

Zach Latta


1 Answers

One Java file can consist of multiple classes with the restriction that only one of them can be public. As soon as you remove public keyword from your classes, you can combine them into a single Java file.

like image 185
Bharat Sinha Avatar answered Oct 06 '22 08:10

Bharat Sinha