If I have a package, can that package have 2 classes with main methods defined?
Yes. You can put/have a
main method in any class. This is a way to allow testing of a class.
If yes, from where the execution will start as there are 2 execution points now.
The jvm looks for a class in a file with the
public modifier and a
main method for/at startup. The name of the source file, the (exact same) name of the class in the file that has the
public modifier and that has a
main method is the starting point. This classes
main method will be the starting point.
In packages you usually have each class in a separate file. If a file has multiple outer classes then you may have only one outer class with the
public modifier in a file.
In java, let's say I have a class "SkyScraper" and run it with "java ScyScraper" at the prompt. Then the jvm looks in the SkyScraper.class file for
public class SkyScraper {
...
/** The jvm looks for this as the starting point. */
public void main(String[] args) {
...
}
}
class WindowWasher {
}