Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
In the absense of parentheses and &&, || operators when considering if the operation of a given operator is performed or not, we must note the precedence of the operators to its left and the precedence of those to its right. An operation is performed before the operators to its left if they have fewer precedence and before the operators to its right if the precedence of those is equal or fewer.
SCJP2. Please Indent your code using UBB Code
Method void main(java.lang.String[])
0 bipush 10
2 istore_1
3 iconst_0
4 invokestatic #2 Method boolean m(int)
7 ifne 24
10 iconst_1
11 invokestatic #2 Method boolean m(int)
14 ifeq 28
17 iconst_2
18 invokestatic #2 Method boolean m(int)
21 ifeq 28
24 iconst_1
25 goto 29
28 iconst_0
29 istore_3
30 getstatic #3 Field java.io.PrintStream out
33 iload_3
34 invokevirtual #4 Method void println(boolean)
37 return
public class Test
{static boolean a, b, c, d, e;
Test(){
e = a && b && c || d;
}
}//the values of the variables won't matter to compiler:
Method Test()
0 aload_0
1 invokespecial #1 Method java.lang.Object()
4 getstatic #2 Field boolean a
7 ifeq 22
10 getstatic #3 Field boolean b
13 ifeq 22
16 getstatic #4 Field boolean c
19 ifne 28
22 getstatic #5 Field boolean d
25 ifeq 32
28 iconst_1
29 goto 33
32 iconst_0
33 putstatic #6 Field boolean e
36 return
SCJP2. Please Indent your code using UBB Code
public class Test
{static int a, b, c, d;
{d = a * b + c;
}
}
Method Test()
0 aload_0
1 invokespecial #1 Method java.lang.Object()
4 getstatic #2 Field int a
7 getstatic #3 Field int b
10 imul
11 getstatic #4 Field int c
14 iadd
15 putstatic #5 Field int d
18 return
SCJP2. Please Indent your code using UBB Code
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
|