Originally posted by Garrett Smith:
When a class is declared w/o a modifier, it can be described as package-private.
What is the result of attempting to compile and run the above program?
a. Prints: P.printS1 P.printS2
b. Prints: P.printS1 Q.printS2
c. Prints: Q.printS1 P.printS2
d. Prints: Q.printS1 Q.printS2
e. Runtime Exception
f. Compiler Error
g. None of the Above
<hr></blockquote>
Can someone clarify what it means to "run" the program? It seems that the question should instead be "What happens when Q.main is called."
Really, there's no way to run this from the command line without any auxiliary code.
What is the wording like on the exam? Like this?
Garrett,
When you declare a public class...that means you can only declare one and only one public class.
If you dont declare any class or interface public as in the above code, it is ok to name the file as any of the existing classes. The runtime will check whether there is a main() method in the class whose name is the filename. Otherwise , a runtime exception is thrown.
On the other hand, when you declare a public class, that should be the name of the file in which other classes can exist. and also the public class must have the main method with the required signature to run.
see this code below
IN the above code, if you name it as Hello1.java, then its main method is run at runtime. If you name it Hello2.java, its main method is run and so on. Play with it and let me know if thats what you wanted to know
Sri