|
-
Apr 15th, 2007, 10:21 AM
#1
Thread Starter
Hyperactive Member
[RESOLVED] Array question in extends class
Code:
class a
{
protected int barr[];
}
class b extends a
{
public b(int barr[])
{
super(barr);
barr[]= new int [4];
}
}
why the above code can not work? how can i correct it?
-
Apr 15th, 2007, 11:14 AM
#2
Re: Array question in extends class
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.
Laugh, and the world laughs with you. Cry, and you just water down your vodka.
Take credit, not responsibility
-
Apr 15th, 2007, 02:12 PM
#3
Thread Starter
Hyperactive Member
Re: Array question in extends class
 Originally Posted by crptcblade
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.

thx for remind.
but assigning array is the step
int barr[];
barr=new barr[4];
................................................................
ok, now I according yr tips,then change it to the following
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];
}
}
but the error is same.
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
-
Apr 18th, 2007, 03:11 PM
#4
Re: [RESOLVED] Array question in extends class
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.
All the buzzt
 CornedBee
"Writing specifications is like writing a novel. Writing code is like writing poetry."
- Anonymous, published by Raymond Chen
Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|