Which method signature do you use at line n1 ?

You are asked to create a method that accepts an array of integers and returns the highest value from that array Given the code fragment:

Which method signature do you use at line n1 ?
A. public int findMax (int [] numbers)
B. static int[] findMax (int max)
C. static int findMax (int [] numbers)
D. final int findMax (int [])

Download Printable PDF. VALID exam to help you PASS.

6 thoughts on “Which method signature do you use at line n1 ?

  1. if we add A “public int findMax(int [] numbers)”, compiler will inform what should be corrected (method defined from main static method should be static as well):

    #javac Test38.java
    Test38.java:4: error: non-static method findMax(int[]) cannot be referenced from a static context
    int max = findMax(numbers);
    1 error

    correction per answer “C” will allow to compile without errors:
    # javac Test38.java

  2. Answer C:

    Calling the findMax() method is happening from a static context without instantiating the class. Therefore, the called method should be static.

  3. 1) main method is static and findMax method is declared outside the main method and it is used inside the main method so it must be static.
    2) we can put the public at the beginning of the findMax method or not. It depends
    Answer is C

  4. Lot of answers are incorrect. How can you guarantee that we will pass. Correct answer is C in above question number 24

Leave a Reply

Your email address will not be published. Required fields are marked *

The reCAPTCHA verification period has expired. Please reload the page.