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;
B is also a correct answer.
A, B and D all three will compile.
Why b fails?
What’s the difference betwen a and e or b and d?
Hi ….
a and b ; will cause duplicate initialization error,ans should be a,e,d…kindly revert if my assumption is wrong
+1 to Team’s answer
I think it can be A, D and E.
B won’t compile because of duplicate definition, C won’t compile because of multiple “int” keywords.
Code below compiles fine:
public static void main(String[] args) {
int a,b,c = 0;
int d,e,F;
int k,l,m = 0;
}
The answer is A and D.
The option E should be :
int k,l, m; =0;
which is what is given in the code snippet in which case it will give an error:
error: illegal start of expression
int k, l, m; = 0;
^