Given:
Public static void main (String [] args) {
int a, b, c = 0;
int a, b, c;
int g, int h, int i, = 0;
int d, e, F;
int k, l, m; = 0;
Which two declarations will compile?
A.
int a, b, c = 0;
B.
int a, b, c;
C.
int g, int h, int i = 0;
D.
int d, e, F;
E.
int k, l, m = 0;
Explanation:
Incorrect answers:
int a, b, c;
OK, but duplicate definition.
I found a vce file asking for three declarations…if you go into both A and B are right to define and initialize local variables, but in this case I would have twice the same variables and this is not possible. Besides D is good as well.
So is there an error on question or in the answer???
If it were me i would pick B & D besides the name of the variable they are exactly alike.
int a, b, c = 0; compiles
int a, b, c; compiles
int g, int h, int i = 0; doesn’t compile (, should be 😉
int d, e, F; compiles
int k, l, m = 0; compiles
So 4 answers are OK
In another exam is so the following differences:
They were asking for three declarations.
Two of them were wrong:
int g, int h, int i = 0; doesn’t compile (, should be 😉
int k, l, m;=0; doesn’t compile (; after m)
So I think this question is stated wrong.
The correct answer is A,D
B -> won’t compile because it is duplicate
C -> won’t compile due to multiple int keywords. Should be :
int g, h ,i=0;
or
int g; int h; int i = 0;
E -> The code snippet says:
int k, l, m; = 0;
If that is the option as well then it won’t compile due to the misplaced ; after m