answersLogoWhite

0


Best Answer

Hmm, let me see, it is technically perfectly legal to have 2 classes in a single file, as long as one class is an inner class of the other: i.e. public class Stevo{ public class Fun{}}. But if you want two separate classes independent of each other the compiler would scream at you about class is public and should be declare in a file named [className].java. To fix this simply follow the compiler's instructions (shocking! the compiler actually was clear about something) and create a new file with the given name. But sometimes an inner class would be helpful, i.e. an iterator for the Abstract Data Type you are implementing.

User Avatar

Wiki User

16y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: If you have two public classes in a java file what will be the error and how will you remove it?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

How many classes should be included in each java file?

You can only have one non-inner public classes per java file and that class name must match the filename. The java file can also have any number of inner classes and anonymous classes.


Is it possible to have more than one public class in the same file?

No. There can be multiple java classes in the same .java file, but the name of the file must match the name of the public class in the file.


What is the meaning of import in java program?

It tells the compiler where to find classes that are outside the file you are editing.It tells the compiler where to find classes that are outside the file you are editing.It tells the compiler where to find classes that are outside the file you are editing.It tells the compiler where to find classes that are outside the file you are editing.


How remove error unable to open the file stdio.h in c?

Reinstall C or update the C library function . stdio.h must be missing


Java runtime error - NoClassDefFoundError -- how to remove this error in java programming?

This error means that there was a call to a nonexistent class, but this was not caught by the compiler since the class existed when the file was compiled but was removed before running the .class file. To fix this problem try restoring any files you deleted to the SAME directory as your .class file. This error can also be fixed by changing the Java classpath to point to the locations of your files. The -cp command line option should help.

Related questions

Can a .java file contain more than one java classes?

Yes, it can. However, there can only be one public class per .java file, as public classes must have the same name as the source file.


How many classes should be included in each java file?

You can only have one non-inner public classes per java file and that class name must match the filename. The java file can also have any number of inner classes and anonymous classes.


Is it possible to have more than one public class in the same file?

No. There can be multiple java classes in the same .java file, but the name of the file must match the name of the public class in the file.


How do you fix file integrity error?

How to Fix file integrity violated Error


What is error 13010 on iTunes?

itunes error 13010 refers to a corrupt itunes library genius file -- to resolve it remove the "itunes library genius.itdb" from your itunes folder and relaunch iTunes


What is the meaning of import in java program?

It tells the compiler where to find classes that are outside the file you are editing.It tells the compiler where to find classes that are outside the file you are editing.It tells the compiler where to find classes that are outside the file you are editing.It tells the compiler where to find classes that are outside the file you are editing.


Explain Error handling during file operations?

explain error handling during file operation?


How do you remove a Default judgment?

You have to get a copy of the case file and go over it and file a Motion to vacate judgment based on, error in service or whatever your defense is. Check your states laws because there is a SOL on you being able to file this motion.


How can you delete a file that has a long file name when each time you try to delete move or rename it you get an Explorer error?

Try Deep Remove, it worked for me. (link moved to related links section)


How remove error unable to open the file stdio.h in c?

Reinstall C or update the C library function . stdio.h must be missing


Java runtime error - NoClassDefFoundError -- how to remove this error in java programming?

This error means that there was a call to a nonexistent class, but this was not caught by the compiler since the class existed when the file was compiled but was removed before running the .class file. To fix this problem try restoring any files you deleted to the SAME directory as your .class file. This error can also be fixed by changing the Java classpath to point to the locations of your files. The -cp command line option should help.


How do you copy error file?

no,