aspose file tools*
The moose likes Mock Exam Errata and the fly likes pl explain Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Mock Exam Errata
Bookmark "pl explain" Watch "pl explain" New topic
Author

pl explain

Anu Kris
Greenhorn

Joined: Oct 01, 2001
Posts: 13
class Q29 {
public static void main(String[] args) {
int j = 0;
Q29 test = new Q29();
try {
for (j=1 ; j < 5 ; j++)
{
j+= j;
}
int i = test.process() / (j = 5);
}
catch (Exception e) {
System.out.println(e);
System.out.println("Value of j = " + j);
}
}

int process() throws Exception {
throw new Exception("Exception Encountered");
}
}
What is the Output?
1.Prints Value of j = 2
2.Throws Arithmetic Exception.
3.Prints java.lang.Exception : Exception Encountered and Value of j = 7.
4.Prints Value of j = 10
5. Prints java.lang.Exception : Exception Encountered and Value of j = 2.
answer is 2:
can anyone explain.Thanks
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Anu,
The answer should be 3.
For an explanation, please see example in JLS 15.7.1.
Anu Kris
Greenhorn

Joined: Oct 01, 2001
Posts: 13
sorry the answer is 3.thanks nain
Anu Kris
Greenhorn

Joined: Oct 01, 2001
Posts: 13
i still have a doubt of how value of j=7...when the loop completes the value of j is 11.Pl correct me is iam wrong
Anu Kris
Greenhorn

Joined: Oct 01, 2001
Posts: 13
i still have a doubt of how value of j=7...when the loop completes the value of j is 11.Pl correct me is iam wrong
Nain Hwu
Ranch Hand

Joined: Sep 16, 2001
Posts: 139
Anu,
Will you tell me why you think j should be 11?
Then, we can discuss it from there. Ok?
Anu Kris
Greenhorn

Joined: Oct 01, 2001
Posts: 13
the value of j at the end of the for loop is 11...i thought so
Anu Kris
Greenhorn

Joined: Oct 01, 2001
Posts: 13
iam sorry.....ignore the previous msg.....value of i=7,i got it.Thanks for the help
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pl explain