Can a public class MyClass be defined in a source file named YourClass.java?

No the source file name, if it contains a public class, must be the same as the public class name itself with a .java extension.
website hit counter