Java is the future !: Quiz of the day | OCPJP - Aug 16, 2011

Tuesday, August 16, 2011

Quiz of the day | OCPJP - Aug 16, 2011


What will be the result of compiling and running the following code:

Options :
a) true
true
b) false
true
c) false
false
d) None of the above



Solution: Correct choice is option B.
Creating a new instance of the class File, you're not yet making an actual file, you're just creating a filename. So file.exists() return false.
createNewFile() method created an actual file. So file.exists() return true.

No comments:

Post a Comment