Results 1 to 4 of 4

Thread: [RESOLVED] Array question in extends class

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Resolved [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?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2007
    Location
    Hong Kong
    Posts
    384

    Re: Array question in extends class

    Quote 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

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594

    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
  •  



Click Here to Expand Forum to Full Width