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

    Question Link objects and calling a variable object's method

    Hello,

    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
    Location
    Northern Virginia, United States
    Posts
    3,618
    Rep Power
    5

    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.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,449
    Rep Power
    25

    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, 04:00 AM
  2. Replies: 1
    Last Post: 10-27-2011, 07: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, 04:10 AM
  4. Calling Object.method
    By Fedor in forum New To Java
    Replies: 1
    Last Post: 04-11-2009, 01: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, 02: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
  •