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?
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;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.