Results 1 to 4 of 4
  1. #1
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default Question about arrays and methods

    Hi there.

    I have a question in respect to arrays and methods. Here goes: I have two classes. One class holds the method while the other class calls the method. The class that calls the method also declares an array. So, it looks like this:

    class 1:

    int array[] = new int[1];

    array[0] = 10;

    MyClass myclass = new MyClass;

    myclass.Method(array parameter?)


    Class 2:

    public void (array parameter?) {

    return array parameter;

    }

    As you can see I am trying to figure out how to call an array within a method of another class. What is the correct way of putting the array parameter? How do I do this? Please help! Thanks! :)

  2. #2
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: Question about arrays and methods

    To call a method in another class you ether need to:
    1. Make a object out of the class and call it by object.mehod();
    2. Make it static then call it by Classname.method();

    You have two choices , pick one And remember to have the get method public . I didn't fully understand your question though.

  3. #3
    BenH is offline Member
    Join Date
    Dec 2011
    Posts
    48
    Rep Power
    0

    Default Re: Question about arrays and methods

    Hey there!

    I am trying to figure out how to use a method call to with an array as the parameter. The array being in the other class. How do I do that? Thanks for your help though :)

  4. #4
    santa's Avatar
    santa is offline Senior Member
    Join Date
    Nov 2009
    Location
    Sweden
    Posts
    208
    Rep Power
    5

    Default Re: Question about arrays and methods

    aha ! you should have mention it before ;) myclass.Method(Arrayname) -> public void method(int[] newArrayName) where int[] should be the type of object you want to give.

Similar Threads

  1. Using Arrays and Overloading Methods.
    By dalek in forum New To Java
    Replies: 5
    Last Post: 10-25-2011, 04:52 AM
  2. Instancing methods in arrays possible?
    By KReative in forum New To Java
    Replies: 9
    Last Post: 10-09-2011, 01:54 PM
  3. Arrays and methods
    By namie in forum New To Java
    Replies: 3
    Last Post: 10-05-2009, 09:43 AM
  4. methods, classes, arrays.. oh my!
    By katalyst in forum New To Java
    Replies: 30
    Last Post: 03-30-2009, 12:57 AM
  5. Arrays & Methods
    By TheRocket in forum New To Java
    Replies: 1
    Last Post: 12-10-2008, 07:37 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •