aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Valentins Mock Exam Question 6 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 "Valentins Mock Exam Question 6" Watch "Valentins Mock Exam Question 6" New topic
Author

Valentins Mock Exam Question 6

sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
public class Question07 {
public static void main(String[] args) throws Exception {
int i=2;
boolean b = true;
throw new Exception("Values are:"+(b!=b)+","+(i=args.length)+","+(b=i==2));
}
}
-----------------------------------------------
When I ran this code it gave me

ava.lang.Exception: Values are:false,0,false
at Question07.main(Question07.java:340)
Exception in thread "main"
Process completed with exit code 1
------------------------------------------------
Why is it so?


Sunita<br />SCJP 1.4
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
(b!=b)
this asks if b is not equal to b. Obviously b is equal to b so this is false.
(i=args.length)
Assuming you entered no arguments when you ran this, args.length = 0 and that is what is assigned to i
(b=i==2));
This asks if i is equal to 2. i is equal to 0 (see above) so that is false and that value (false) is assigned to b.
[ October 07, 2002: Message edited by: Thomas Paul ]

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
sun par
Ranch Hand

Joined: Oct 03, 2002
Posts: 257
Thanks...
Gautam Jha
Greenhorn

Joined: Sep 23, 2002
Posts: 10
throw new Exception("Values are:"+(b!=b)+","+(i=args.length)+","+(b=i==2));
b != b is always false
i=args.length: i is assigned 0
b=i==2 translates to (b =(i==2)). i value is 0, so i==2 is false, which is assigned to b.
Hence the answer.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Valentins Mock Exam Question 6