Results 1 to 3 of 3
  1. #1
    Fotis is offline Member
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0

    Default call method in another class with array ? (is possible?)

    Hi!

    I have one small question. Is that possible?

    Java Code:
    public class test1 {
        public static void main (String[] args){
            test2 client = new test2();
            test2[] call = new test2[1000];
            int x =2;       
            call[1].add1(x);
        }
    }
    and

    Java Code:
    public class test2 {    
        void add1(int x) { 
            x = x+1;
        }
    }
    Sorry for my bad English.

  2. #2
    DeNiS_M is offline Member
    Join Date
    Sep 2011
    Location
    Athens Greece
    Posts
    29
    Rep Power
    0

    Default Re: call method in another class with array ? (is possible?)

    It is legal piece of code. You allocate an array of test2 object in line 4
    and you call one of the class method in line 6.Although it does nothing to change the value of variable x;

  3. #3
    Fotis is offline Member
    Join Date
    May 2012
    Posts
    6
    Rep Power
    0

    Default Re: call method in another class with array ? (is possible?)

    Hi.

    I found the solution.

    It also need this line of code:

    Java Code:
    call[1] = client;

Similar Threads

  1. read or call an array from other class an method
    By ki_ha1984 in forum New To Java
    Replies: 5
    Last Post: 01-23-2012, 11:42 PM
  2. Inner class method call
    By d915172 in forum New To Java
    Replies: 3
    Last Post: 11-11-2010, 10:40 PM
  3. Replies: 2
    Last Post: 05-01-2010, 09:59 AM
  4. How to call a method from another class?
    By jboy in forum New To Java
    Replies: 8
    Last Post: 09-09-2009, 08:29 AM
  5. How to call a class within a method
    By Manfizy in forum New To Java
    Replies: 3
    Last Post: 03-19-2009, 01:34 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
  •