Results 1 to 3 of 3
  1. #1
    Wice is offline Member
    Join Date
    Jun 2014
    Rep Power

    Question Link objects and calling a variable object's method


    I've been searching quite a while for an answer but seeing as I could not find it, I decided to come here, hoping someone could help me.

    Say I have two classes, Author and Book, and I have 2 author objects and 10 book objects. I would like to know how to do two things:

    1) Make some sort of connection that makes clear that author X wrote books A, B and F.

    2) Call a method from a book object that is connected to an author.

    Seeing as I don't know which books will be connected to an author, is there some way to call a method of an object bases on a variable object name? Something like call the getFirstPage() method for every book that is linked to author X?

    Many thanks in advance!

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    Default Re: Link objects and calling a variable object's method

    The Author class can have the author's name and other relevant info. Then author class can also have a list of books the author wrote whch can be added with an addBook method. The book class can have a field with the author's name. When you create a book you can set the authors name. Or you can set the authors name when you add the book to the author class. You need to make certain that no one can change these fields by changing an authors name or adding a book to the incorrect author. That is the tricky part of the exercise.

    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Eastern Florida
    Rep Power

    Default Re: Link objects and calling a variable object's method

    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. Calling a Method in all Objects of a Class
    By Tman in forum New To Java
    Replies: 1
    Last Post: 04-19-2012, 05:00 AM
  2. Replies: 1
    Last Post: 10-27-2011, 08:16 AM
  3. same object variable t and same methods is calling
    By javastuden in forum New To Java
    Replies: 1
    Last Post: 11-24-2009, 05:10 AM
  4. Calling Object.method
    By Fedor in forum New To Java
    Replies: 1
    Last Post: 04-11-2009, 02:44 PM
  5. Calling a method for all instances of an object
    By rattle in forum New To Java
    Replies: 4
    Last Post: 04-30-2008, 03:10 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