public class pes{
public static void main(String args[]){
Computer[] c=new Computer[3];
Computer c[0]= new Computer("Jayu",66,10,20,30,40,50);
for(int i=0;i<3;i++){
c[i].d();
}
}
}
I am getting ']' expected pointing at 0 and illegal start of expression pointing at ']' bracket before equals to sign..!!
The Computer
part in your assignment is invalid - you're trying to declare anything. It should just be:
c[0] = new Computer(...);
At that point it will compile - but you'll get a NullPointerException
when i
is 1. You'll need to either check whether c[i]
is null before dereferencing it, or make sure you popuate the whole array rather than just the first element.
See more on this question at Stackoverflow