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;

Explanation:
Incorrect answers:
int a, b, c;
OK, but duplicate definition.



Leave a Reply 8

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


Nur

Nur

C.
int g, int h, int i = 0;

There is a typo in C. A comma should be in place after int i.

It should be:
C.
int g, int h, int i, = 0;

Also a semicolon was forgotten in E:

E.
int k, l, m; = 0;

sree

sree

According to options A,B,D,E compile without any error

lolwut?

lolwut?

sree, are you serious? lol.

You must have done it wrong for you to have them almost all compile without error.

B cannot be compiled because a, b, c were already initialized.

C cannot be compiled because if you entered those correctly in your Netbeans(for me), an error saying ” expected” for all 3 would be displayed.

E cannot be compiled because of that semicolon after m.

lolwut?

lolwut?

Excuse me…. expected was what I was saying there….

lolwut?

lolwut?

*Identifier expected.

Jazz

Jazz

“A,D” is the answer

Explanation:

Consider it is in the same file and Top to Bottom Declarations.

//line 1 int a, b, c = 0; //good and compiles
//line 2 int a, b, c; // as we have a,b,c variables declared in line 1 this line is wrong and will not compile.
//line 3 int g, int h, int i, = 0; // Compile Time Error
//line 4 int d, e, F; // good and complies
//line 5 int k, l, m; = 0; // Compile Time Error.

James

James

The Answer is A, D.

surfo

surfo

Definitivamente la A y la D.
-La B no puede ser por que se repite el nombre de las variables.
-La C no puede ser por que es error de sintaxis.
-La D no puede ser por que es error de sintaxis;