why the above code can not work? how can i correct it?Code:class a
{
protected int barr[];
}
class b extends a
{
public b(int barr[])
{
super(barr);
barr[]= new int [4];
}
}
Printable View
why the above code can not work? how can i correct it?Code:class a
{
protected int barr[];
}
class b extends a
{
public b(int barr[])
{
super(barr);
barr[]= new int [4];
}
}
Well, first, class a doesn;t define a constructor that takes in an int array. Next, it's bee a while, but I don't think you need the [] when assigning to the array.
And for future reference, it would make things easier on the people looking at your problem if you would list any compiler errors you are getting.
:)
:D thx for remind.Quote:
Originally Posted by crptcblade
but assigning array is the step
int barr[];
barr=new barr[4];
................................................................
ok, now I according yr tips,then change it to the following
but the error is same.Code:class a
{
protected int barr[];
public a(int barr[])
{
this.barr=barr;
}
}
class b extends a
{
public b(int barr[])
{
super(barr);
barr[]= new int [4];
}
}
Code:C:\Documents and Settings\Ying\a.java:15: not a statement
barr[]= new int [4];
^
C:\Documents and Settings\Ying\a.java:15: ';' expected
barr[]= new int [4];
^
2 errors
Tool completed with exit code 1
The compiler tells you exactly what's wrong. You cannot have barr[] in a statement. It's simply illegal.
Just remove the line. It's an effective no-op anyway. But if you wanted to assign to barr (note that you would be modifying the constructor parameter, not the member), you would remove the []. As blade said, you don't need it in an assignment.