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 6 of 6

Thread: Confused about invoking methods?

  1. #1
    Junior Member ShamelessTeenie's Avatar
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Confused about invoking methods?

    Hi, sorry for the extremely basic question, but I'm confused about something. I'm studying for my next computer science exam, and looking over past tests. One of the questions gives us three different methods and asks us to write statements to invoke them, which sounds really easy, and I thought that I had done it correctly. However, my professor gave us the correct output, and apparently, when you invoke a method and run the program, Java is supposed to output "methodWhatever has been invoked.", which my program isn't doing.

    I'm very confused. I thought that to invoke a method, all you had to do was pass it actual arguments that correspond to the method's parameters, but I'm doing that, and I'm still not getting any output. Maybe I'm missing something?

    These are the methods that we're supposed to invoke:
        public int fancyOpA (int x, String y){
           return 0;
        }
        public double fancyOpB (int x, double y){
            return 0;
        }
        public static double fancyOpC (int x, int y){
           return 0;
        }

    And here are the statements that I have to invoke them:

         int invokeA = fancyOpA(6, "bluh");
         double invokeB = fancyOpB(6, f);
         double invokeC = fancyOpC(6,7);


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

    Default Re: Confused about invoking methods?

    The posted methods do nothing with the args passed to them and all return a value of 0.

    Java is supposed to output "methodWhatever has been invoked.", which my program isn't doing.
    Do you have a "special" version of java that does that? The version of java in the jre/JDK does not output any messages when a method is invoked.
    If you don't understand my answer, don't ignore it, ask a question.

  3. #3
    Junior Member ShamelessTeenie's Avatar
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Confused about invoking methods?

    I know the methods don't do anything with the args. I didn't write those--they were just the methods that were given on the test question, so I don't think they're supposed to really serve any practical purpose.

    I don't have any special version of java, just the version in the JDK, so that's weird. I didn't think that it was supposed to output any messages when I invoked a method, but the test solution that he gave us (he didn't give us the correct codes, just the output messages that you'd get from the correct codes) said that when we invoked the methods, we should get a message telling us so.

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

    Default Re: Confused about invoking methods?

    said that when we invoked the methods, we should get a message telling us so.
    There must be something missing. What you've posted won't output anything.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    ShamelessTeenie (April 9th, 2013)

  6. #5
    Junior Member ShamelessTeenie's Avatar
    Join Date
    Apr 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Confused about invoking methods?

    In that case, do you have any idea how I would code it to output the message? I'm sorry, to ask, but I'm lost. It says on the question that the statements to invoke the methods should only be one line of code each, so I don't know how I would do that, and I'm pretty sure we haven't covered anything like it in class.

    The question is very confusing, because it simply gives us the three methods, then tells us to write one-line statements invoking them, which I believe I did correctly. The test question itself didn't say anything about outputting anything-- that part was only on the solution sheet.

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

    Default Re: Confused about invoking methods?

    For the methods to print out a message when they are called, you would have to add a call to the println() method to the methods being called.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Invoking JavaScript in Servlet
    By yash188 in forum Java Servlet
    Replies: 3
    Last Post: September 17th, 2012, 10:24 PM
  2. Why and where abstract methods & classes and static methods are used?
    By ajaysharma in forum Object Oriented Programming
    Replies: 7
    Last Post: July 14th, 2012, 01:16 AM
  3. [SOLVED] Invoking a superclass constructor in my subclass
    By kari4848 in forum Object Oriented Programming
    Replies: 5
    Last Post: April 29th, 2011, 01:12 PM
  4. Replies: 0
    Last Post: January 17th, 2011, 05:14 AM
  5. [SOLVED] Array of objects, invoking constructor for one changes others
    By BigFoot13 in forum Object Oriented Programming
    Replies: 4
    Last Post: October 24th, 2010, 01:30 PM