Click to See Complete Forum and Search --> : declaration of variable


dell_compu
July 13th, 2000, 06:25 PM
This is the Question I came across in Java2 Exam:

Which statement declares a variable a which is suitable for referring to an array of 50 strings objects?
A.char a[][];
B.String a[];
C.String []a;
D.Object a[50];
E.String a[50];
F. Object a[];

It is given somewhere that B,C,F are correct.Why not E correct because we can declare and initialize at the same time....why F is correct?is it because String extends Object??

will anyone give me the correct answer for this question? will u please explain me in detail....

Thanks,
dd

Eugen SEER
July 14th, 2000, 10:50 AM
Hi,
B and C are correct, in Java it is allowed to place the brackets either before or after the name. E is wrong, because the number of elements must be on the right hand side of the equal sign.
Declaration:
String a[];
Full:
String a[] = new String[50];