0

I am required to save and submit my program as only one file. My program has multiple classes and from what I understand so far is that only the main class can be public? What changes would I have to make?

These are the instructions give by our professor:

When you submit your project you should submit only one named xxxx.java The main class in this file must be a public class but no other classes that you use can be public (because only one public class is allowed in a file).

Lola
  • 31
  • 1
  • 4

2 Answers2

1

You can submit several public classes in a single file, but it won't compile. Java requires you to have a single public class per .java file, which matches file name exactly. The rest of the classes in the file can be with other access modifiers.

nemanja228
  • 556
  • 2
  • 16
0

You can save the other classes in the same file. However on Java you can only have one public class per file. The other classes can not be public.

Tito
  • 102
  • 9
  • So what you're saying is that I copy the other classes into the main class file and for example remove the "public" from "public class A" ? – Lola Dec 13 '18 at 01:42
  • The main class (the class with the main method) will be public. Below that class will be the other classes but they will not use public. (Don't give them an access modifier) Example public class MainClass { // code } class NextClass { // code } – Tito Dec 13 '18 at 01:45