File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Mock Exam Errata and the fly likes Mock Exam -4test.com Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "Mock Exam -4test.com" Watch "Mock Exam -4test.com" New topic
Author

Mock Exam -4test.com

Mukti Bajaj
Ranch Hand

Joined: Dec 11, 2000
Posts: 59
Hello,
boolean flag = false;
if (flag = true) {
System.out.println("true");
} else {
System.out.println("false");
}
}
A.true is printed to standard out
B.false is printed to standard out
C.An exception is raised
D.Nothing happens
The answer to above question is A....and I have checked by typing the code as well....that also gives answer as A.
But, I am unable to understand the reason for this...Please can you explain.....
Thanks.
c stet
Greenhorn

Joined: Jan 04, 2001
Posts: 1
The line if(flag = true) sets the value of flag to true
and then the if evalutes flag to see if it is true. To
have the else statement execute you would need yo have
the code use ==
Originally posted by Mukti Bajaj:
Hello,
boolean flag = false;
if (flag = true) {
System.out.println("true");
} else {
System.out.println("false");
}
}
A.true is printed to standard out
B.false is printed to standard out
C.An exception is raised
D.Nothing happens
The answer to above question is A....and I have checked by typing the code as well....that also gives answer as A.
But, I am unable to understand the reason for this...Please can you explain.....
Thanks.

Vineet Sharma
Ranch Hand

Joined: Dec 30, 2000
Posts: 51
Hi!
The trick, here is with the operator used! Note that it is =operator(Assingment Operator) and not the ==operator(Equality Operator).
From the mock exams I have taken I feel one needs to be extremely Attentive with the questions as well as the answer choices.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Mock Exam -4test.com