Which two declarations will compile?

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?

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;



Leave a Reply 6

Your email address will not be published. Required fields are marked *


Team

Team

B is also a correct answer.

A, B and D all three will compile.

kabal

kabal

Why b fails?
What’s the difference betwen a and e or b and d?

pesari

pesari

Hi ….

a and b ; will cause duplicate initialization error,ans should be a,e,d…kindly revert if my assumption is wrong

tom

tom

+1 to Team’s answer

drmorriarti

drmorriarti

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;
}

nisha

nisha

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;
^