Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Accessing array of method

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Accessing array of method

    Hi.
    I was wondering how do I access whole bunch of array of method.
    tom is an array of object.
    Student[] tom = new Student[10];
     
    for(int i = 0; i < 10; i++){
    	tom[i] = new Student();
    }

    tom[].accessMethod(); //Not working

    Error Message: class expected and ; expected .What to do?


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Accessing array of method

    Which element is tom[]?

    compare to tom[i] = new Student() where tom[i] = the ith element in tom

  3. #3
    Junior Member
    Join Date
    Oct 2012
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Accessing array of method

    I mean. I want to pass the entire array into the method. Is it possible? Like : tom[1 to 100] array <--I know it's wrong but it's for illustrate purpose only.

  4. #4
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Accessing array of method

    You're asking a couple different things.

    Do you want to pass the entire array into a method? Then you just pass the tom variable like you'd pass any other variable.

    Do you want to access a method of each instance of Student in your tom array? If so, iterate over the list an access it like so:

    someArray[someIndex].someMethod();
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

Similar Threads

  1. accessing class method problem
    By steel55677 in forum Object Oriented Programming
    Replies: 11
    Last Post: February 23rd, 2012, 08:50 PM
  2. [SOLVED] Accessing && Editing properties of objects in an array. Plus a few more questions.
    By CameronFaust in forum Collections and Generics
    Replies: 31
    Last Post: August 10th, 2011, 07:35 PM
  3. Accessing static method
    By argolian in forum What's Wrong With My Code?
    Replies: 4
    Last Post: February 16th, 2011, 01:44 PM
  4. Accessing a method of one class in another class
    By Sai in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 23rd, 2010, 04:06 PM
  5. [SOLVED] Problem accessing specific data in an array and getting it to return properly
    By Universalsoldja in forum Collections and Generics
    Replies: 3
    Last Post: February 4th, 2010, 04:26 PM