Passing a Method?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Daniel101
    New Member
    • Apr 2010
    • 1

    Passing a Method?

    Hello, I'm still new to Java and I have a certain problem in my code.

    I've made 2 classes (Person and Group) and 1 demo (Which is used for testing my classes).

    Person works perfectly fine when I use it along with my demo.
    Though, I'm having a bit of trouble importing/using certain methods from Person in Group.
    The problem is that I do not know how to import/use a method from another class in my Group class (Yes I'm a beginner).
    For example:
    In my Person class
    I need to pass on the (getNumMem) Method into my Group class to be used.
    Code:
    public int getNumMem(){
    return numMem;
    }
    The error message I get when trying to run this in Group is:
    cannot find symbol - method getNumMem();

    So, I was wondering if any of you could kindly explain to me how I would be able to do this?

    ~Your help is greatly appreciated!
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    Originally posted by Daniel101
    Hello, I'm still new to Java and I have a certain problem in my code.

    I've made 2 classes (Person and Group) and 1 demo (Which is used for testing my classes).

    Person works perfectly fine when I use it along with my demo.
    Though, I'm having a bit of trouble importing/using certain methods from Person in Group.
    The problem is that I do not know how to import/use a method from another class in my Group class (Yes I'm a beginner).
    For example:
    In my Person class
    I need to pass on the (getNumMem) Method into my Group class to be used.
    Code:
    public int getNumMem(){
    return numMem;
    }
    The error message I get when trying to run this in Group is:
    cannot find symbol - method getNumMem();

    So, I was wondering if any of you could kindly explain to me how I would be able to do this?

    ~Your help is greatly appreciated!
    I have a feeling that numMem should not be contained within a Person object. A person generally shouldn't have any knowledge of how many members there are. They have to check the group as a whole, to get that knowledge.


    If you're keeping the same design then:
    Get a member of type person, and ask that person how many members there are.

    Comment

    Working...