Link to home
Start Free TrialLog in
Avatar of spoggles
spoggles

asked on

Accessing Methods of Objects in ArrayLists

I am still fairly new to Java and I'm trying to understand Array Lists better. If you create an Array List and put objects within the Array List, how can you access the methods of the object?

For example, the code below is just a simple Book class. If I were to write this code:

   ArrayList booksList = new ArrayList();
   Book myBook = new Book();
   booksList.add(myBook);

How would I access the getAuthor method of myBook?
public class Book
{
     public string Author;
     public string Title;
     
     public String getAuthor() {
       return Author;
     }
}

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial