TestAddress.java
Address[] adrsarr = new Address[5];
adrsarr[0] = new Address("B402", "3", "42", "Behind Sector 9",
"New Delhi", "Delhi", "Delhi", "India", "232113");
adrsarr[1] = new Address("B1", "2", "61", "Bb Road 2", "Mumbai",
"Mumbai", "Maharashtra", "India", "1213");
adrsarr[2] = new Address("AH2", "325", "98", "BPGC", "Goa", "Goa",
"Goa", "India", "403726");
adrsarr[3] = new Address("a222", "2", "81", "Sector market",
"New Delhi", "Delhi", "Delhi", "India", "11a001");
Address.java has a constructor of type Address()
and of Address(string, string, string, string, string, string, string, string, string)
Now this given code does not work inside the main TestAddress class, it gives an error on the line where I'm declaring adrsarr
- Syntax error on token ";", { expected after this token
But if I put it inside a function like buildArr(), then it compiles flawlessly, no errors.
Any idea what's happening? How am I supposed to initialize an object array without making a function?