Results 1 to 7 of 7
  1. #1
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Default Accessing arrays in another class

    How can I access an array of objects that is held as private instance member in another class; just for retreiving the value. I mean Ive tried accessing it as if it was a instance variable, but I get the compile error: Illegal start of type

    Class A:
    Array(objects)

    Class B:
    Access Array elements from Class A

    Please reply...

  2. #2
    rosh72851 is offline Member
    Join Date
    Sep 2008
    Posts
    58
    Rep Power
    0

    Default

    Never mind....

  3. #3
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

  4. #4
    ianjedi is offline Member
    Join Date
    Oct 2008
    Posts
    21
    Rep Power
    0

    Default

    Quote Originally Posted by rosh72851 View Post
    How can I access an array of objects that is held as private instance member in another class; just for retreiving the value. I mean Ive tried accessing it as if it was a instance variable, but I get the compile error: Illegal start of type

    Class A:
    Array(objects)

    Class B:
    Access Array elements from Class A

    Please reply...
    You would set a public setter/getter method in the same class as the private variable you want access to allow them to be set under control of the method.

    cheers

    Ian J

  5. #5
    Supamagier is offline Senior Member
    Join Date
    Aug 2008
    Posts
    384
    Rep Power
    7

    Default

    Use protected or public.
    I die a little on the inside...
    Every time I get shot.

  6. #6
    presh4u Guest

    Default

    public is needed to access

  7. #7
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by presh4u View Post
    public is needed to access
    What you mean? Is this an answer or a question. It's much better to explain much more clear what you want to do.

Similar Threads

  1. Accessing list out another class
    By Preethi in forum New To Java
    Replies: 23
    Last Post: 10-26-2008, 02:54 PM
  2. Replies: 0
    Last Post: 02-17-2008, 09:03 AM
  3. Replies: 0
    Last Post: 02-17-2008, 09:01 AM
  4. Inner class accessing outer class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-17-2008, 08:59 AM
  5. Replies: 5
    Last Post: 01-03-2008, 07:54 AM

Posting Permissions

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