Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Dealing with two Classes : Using method from one Class as a parameter to another

  1. #1
    Junior Member
    Join Date
    Apr 2012
    Posts
    9
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Dealing with two Classes : Using method from one Class as a parameter to another

    Is using a method from one class as a parameter for another class possible?

    Example :

    Class1 method:
    PHP Code:
    public void initialA ()
    {
    if(
    a<b)
      
    a++;
    else
      
    b++;

    if(
    money == 2)
    money++;

    Now making a method for my Class2(Different class file from Class1), is it possible to take ONLY initialA's results of "money++" as one of my parameter, and not take the results of a++ or b++ (assuming these are all int) ?


    thanks
    Last edited by red7; April 14th, 2012 at 12:47 PM.


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,145
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Dealing with two Classes : Using method from one Class as a parameter to another

    I'm not sure what your question is.
    You can not pass a method as a parameter to another method. You can pass a reference to an instance of a class that has the desired method as a parameter in method call.

    When you call a method like initialA(), it will execute its statements in the order they are coded. The caller can not specify which statements are to be executed. The initialA() method would have to be specially coded and take a parameter that would tell it what to do.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Shouldn't "list" be a parameter of the method Create()?
    By wholegrain in forum Object Oriented Programming
    Replies: 6
    Last Post: February 13th, 2012, 12:40 AM
  2. Using a method to add two classes and produce a third
    By shamman84 in forum Object Oriented Programming
    Replies: 6
    Last Post: February 5th, 2012, 09:18 PM
  3. how can i pass objects into a parameter and display them in the method
    By em1980 in forum What's Wrong With My Code?
    Replies: 14
    Last Post: December 5th, 2011, 01:02 PM
  4. Help with code dealing with parallel arrays.
    By danielp1213 in forum What's Wrong With My Code?
    Replies: 5
    Last Post: November 13th, 2011, 07:43 PM
  5. Paint program adding classes to main method class
    By Maxfmc in forum What's Wrong With My Code?
    Replies: 0
    Last Post: April 15th, 2011, 07:01 PM