jQuery in Action, 3rd edition
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes easy question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "easy question" Watch "easy question" New topic

easy question

may leung

Joined: Nov 28, 2000
Posts: 23
public class Base{

private void test() {

boolean flag = false;
System.out.println("001 Flag is true");
else {
if (flag=true)
System.out.println("002 Flag is true");
System.out.println("003 Flag is false");


static public void main(String[] a) {
new Base().test();

Select most appropriate answer.
a) 001 Flag is true
b) 002 Flag is true
c) 003 Flag is false
d) None
the ans is b, can anyone explain this to me? thanks~~
Michael Ernest
High Plains Drifter

Joined: Oct 25, 2000
Posts: 7292

This kid of question tests your recognition of the difference between the assignment operator (flag=true) and the equality test (flag==true).
The test: if (flag=true) succeeds if the assignment statement succeeds. flag is a boolean variable, so the assignment is ok because true is a boolean value. This branch therefore will execute its code.
Michael Ernest, co-author of:
The Complete Java 2 Certification Study Guide
[This message has been edited by Michael Ernest (edited December 27, 2000).]

Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
may leung

Joined: Nov 28, 2000
Posts: 23
I get it!
I agree. Here's the link: http://aspose.com/file-tools
subject: easy question
It's not a secret anymore!