K. Tsang CEng MBCS PMP PMI-ACP OCMJEA OCPJP
K. Tsang wrote:Hi there
Given the question, choice A is indeed correct. Why? First look more closely to the location of the GetJar.java and MyJar.jar files.
waleed qureshi wrote:
As you can see in Console1. png, when I try to compile and run it as option A, it compiles fine but doesn't execute successfully and gives 'Exception in thread "main" java.lang.NoClassDefFoundError: GetJar'.
waleed qureshi wrote:
But as you can see in the third attachment - Console 2.png, I try to run it by 'java -classpath .; GetJar', it runs successfully and returns the result 8.
gurpeet singh wrote:
keep in mind that by default java , javac will look for classfile or sourcefile in current directory
waleed qureshi wrote:
gurpeet singh wrote:
keep in mind that by default java , javac will look for classfile or sourcefile in current directory
But I think the authors have mentioned in the book that by default javac looks into the current directory but java doesn't, you have to explicitly specify it. So could you please correct me if I am wrong on this?
And yeah I am clear about the question now, that was my original post that I believed none of the answers are right. Thanks for clearing that and sharing the errata link.
Waq
Don't get me started about those stupid light bulbs. |