Java Methods Quiz Questions And Answers

Approved & Edited by ProProfs Editorial Team
The editorial team at ProProfs Quizzes consists of a select group of subject experts, trivia writers, and quiz masters who have authored over 10,000 quizzes taken by more than 100 million users. This team includes our in-house seasoned quiz moderators and subject matter experts. Our editorial experts, spread across the world, are rigorously trained using our comprehensive guidelines to ensure that you receive the highest quality quizzes.
Learn about Our Editorial Process
| By Raphord
R
Raphord
Community Contributor
Quizzes Created: 2 | Total Attempts: 10,883
Questions: 15 | Attempts: 6,392

SettingsSettingsSettings
Java Methods Quiz Questions And Answers - Quiz

Can you pass this test that has basic Java methods quiz questions and answers? Try your luck, buddy! In order to learn how to use and write methods in Java, we must first start by knowing some of the words. This quiz provides you with a different way of learning the terms so that you can read the questions that you will have on the test and final exam. So, let's find out how much you know!


Questions and Answers
  • 1. 

    In the following method declaration, what is the return type? public static int myMethod(int count, double value) {     return 4; }

    • A.

      Int

    • B.

      Void

    • C.

      Double

    • D.

      MyMethod

    • E.

      Count

    • F.

      Value

    Correct Answer
    A. Int
    Explanation
    The return type of a method is the word given just before the name of the method.

    Rate this question:

  • 2. 

    In the following method declaration, what is the name of the method? public static void showMenu(String category) { }

    • A.

      Public

    • B.

      Category

    • C.

      String

    • D.

      ShowMenu

    Correct Answer
    D. ShowMenu
    Explanation
    The name of the method is always the word just before the "(".

    Rate this question:

  • 3. 

    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG) public static void main(String [] args) {      System.out.print("A");      processRequest();      System.out.print("B");      System.out.print("C");      showMenu();      System.out.print("D"); } public static void showMenu() {     System.out.print("Q"); } public static void eraseFile() {    System.out.print("T"); } public static void processRequest() {   System.out.print("2"); }

    • A.

      A2BCQD

    • B.

      AY2E92

    • C.

      AU9283

    • D.

      A728SA

    Correct Answer
    A. A2BCQD
    Explanation
    The main method first prints "A", then calls the processRequest method which prints "2". After that, it prints "B" and "C" in order. Then, it calls the showMenu method which prints "Q". Finally, it prints "D". Therefore, the output of the main method is "A2BCQD".

    Rate this question:

  • 4. 

    Write a method declaration (just the first line but include the {) for the following description.  The wording must be exact and correct!The method must be called calculateFinalExam.  The method must return a double.  The method accepts 3 parameters:1. the studentId which must be an integer2. the studentName which must be a String3. the testScore which must be a double.

    • A.

      Public static double calculateFinalExam(int studentId, String studentName, double testScore) {

    • B.

      Public static single calculateFinalExam(int studentId, String studentName, double testScore) {

    • C.

      Public static double calculateFinal(int studentId, String studentName, double testScore) {

    • D.

      Public static double calculateExam(int studentId, String studentName, double testScore) {

    Correct Answer
    A. Public static double calculateFinalExam(int studentId, String studentName, double testScore) {
    Explanation
    The correct answer is "public static double calculateFinalExam(int studentId, String studentName, double testScore) {". This is the correct method declaration because it follows all the requirements given in the description. The method is named calculateFinalExam, it returns a double, and it accepts three parameters: an integer for studentId, a String for studentName, and a double for testScore.

    Rate this question:

  • 5. 

    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG) public static void main(String [] args) {      System.out.print("A");      processRequest();      processRequest();      showMenu();      eraseFile();      System.out.print("B"); } public static void showMenu() {     System.out.print("Q"); } public static void eraseFile() {    System.out.print("T"); } public static void processRequest() {   System.out.print("2"); }

    • A.

      A22QBT

    • B.

      AYEI2KDK

    • C.

      A668DQY

    • D.

      A22QTB

    Correct Answer
    D. A22QTB
    Explanation
    The output of the main() method is "A22QTB". This is because the main() method first prints "A", then calls the processRequest() method twice, which prints "2" twice. Then, the main() method calls the showMenu() method, which prints "Q". After that, the main() method calls the eraseFile() method, which prints "T". Finally, the main() method prints "B".

    Rate this question:

  • 6. 

    What word is missing below (fill in the ___________).  Write a method declaration called increase temperature, which takes 2 integers as formal parameters. The two parameters represent the upper and lower targets. The method returns the difference between the upper and lower targets as an integer. public static __________  increaseTemperature(int upper, int lower) {     return upper - lower; }

    • A.

      Ink

    • B.

      Int

    • C.

      Tni

    • D.

      Ttn

    Correct Answer
    B. Int
    Explanation
    The correct answer is "int" because it is the missing word in the method declaration. The method is declared as public static int increaseTemperature(int upper, int lower), indicating that the method will return an integer value. The method calculates the difference between the upper and lower targets and returns it as an integer.

    Rate this question:

  • 7. 

    What is the output of this main() method?  Put the letters into the answer box provided with no spaces between (i.e. ABCEDFG) public static void main(String [] args) {     int value;     System.out.print("@");     v = getRemoteId();     System.out.print(v);     System.out.print("E");     v = getStudentCount();     System.out.print(v);     System.out.print("F");     v = getMonitorCount();     System.out.print("W");     } public static int getRemoteId() {    return 3; } public static int getMonitorCount() {   return 2; } public static int getStudentCount() {   return 6; }

    • A.

      @DKSLA

    • B.

      @63DLS

    • C.

      @3E6FW

    • D.

      @23JFL

    Correct Answer
    C. @3E6FW
    Explanation
    The main() method starts by printing "@" and then calls the getRemoteId() method, which returns the value 3. The value 3 is then printed. Next, the method prints "E" and calls the getStudentCount() method, which returns the value 6. The value 6 is printed. Finally, the method prints "F" and calls the getMonitorCount() method, which returns the value 2. However, the value is not printed as there is a missing print statement. Therefore, the correct output is "@3E6FW".

    Rate this question:

  • 8. 

    What is the output of this main() method?  Put the letters into the answer box provided with no spaces between (i.e. ABCEDFG) public static void main(String [] args) {      showMenu();      eraseFile();      System.out.print("B");      showMenu(); } public static void showMenu() {     System.out.print("Q");     eraseFile(); } public static void eraseFile() {    System.out.print("T"); } public static void processRequest() {   System.out.print("2"); }

    • A.

      WUDYEW

    • B.

      QUDOWO

    • C.

      QCHSAL

    • D.

      QTTBQT

    Correct Answer
    D. QTTBQT
    Explanation
    The output of the main() method is "QTTBQT".
    The showMenu() method is called twice in the main() method. Inside the showMenu() method, "Q" is printed and then the eraseFile() method is called, which prints "T". This sequence is repeated twice, resulting in "QTT" being printed. Then, "B" is printed from the main() method. Finally, the showMenu() method is called again, printing "Q" and then the eraseFile() method is called, printing "T". So, the overall output is "QTTBQT".

    Rate this question:

  • 9. 

    What is the output of this main() method?  Put the letters into the answer box provided wih no spaces between (i.e. ABCEDFG) public static void main(String [] args) {     int value;     int x;     x = 3;     System.out.print("A");     value = checkLength(x);     System.out.print("B");     System.out.print(x);     System.out.print(value); } public static void loadSong(int id) {    System.out.print(id); } public static int checkLength(int id) {   System.out.print(id);   id = id + 4;   System.out.print(id);   return 9; } public static int getStudentCount() {   return 6; }

    • A.

      A37B39

    • B.

      A68B90

    • C.

      A7D7BJ

    • D.

      ATIE78O

    Correct Answer
    A. A37B39
    Explanation
    The output of the main() method is "A37B39". The program first prints "A" and then calls the checkLength() method with the value of x (which is 3) as an argument. Inside the checkLength() method, the value of id is printed (3), then it is incremented by 4 (resulting in 7), and then it is printed again (7). The checkLength() method returns 9. Back in the main() method, "B" is printed, followed by the value of x (3), and then the value returned by the checkLength() method (9). Therefore, the final output is "A37B39".

    Rate this question:

  • 10. 

    In the following method declaration, how many formal parameters are there?public static double squareRoot(double value) {  return 2.3;}

    • A.

      0

    • B.

      1

    • C.

      2

    • D.

      None; methods do not have formal parameters

    Correct Answer
    B. 1
    Explanation
    The parameter list is all the things between the "(" and the ")". You just need to count how many items are in the list... each one will have a comma between them.

    Rate this question:

  • 11. 

    In the following method, how many values are returned? public static void syncPhone(int idNumber) { }

    • A.

      0

    • B.

      1

    • C.

      2

    • D.

      4

    Correct Answer
    A. 0
    Explanation
    A method can return only one type! This time the return type is void, so there is nothing returned from this method at all.

    Rate this question:

  • 12. 

    The following code in the main is valid:public static void main(String [] args) {    int value;    value = createGameCharacter();    // rest of program}public static void createGameCharacter() {}

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The return type of createGameCharacter() is void. You cannot store the return into the variable value.

    Rate this question:

  • 13. 

    True or False. The call to the method installApplication() is valid:public static void main(String [] args) {   installApplication("Angry Birds", "version 1.2");}public static void installApplication(String appName, int appVersion) {  // rest of method not important}

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The second parameter called appVersion is an integer. In the main method we are trying to call with the method with a string as the second parameter.

    Rate this question:

  • 14. 

    The following code in the main is valid:public static void main(String [] args) {    int value;    value = depositMoney(amount);    // rest of program}public static int depositMoney() {   return 4;}

    • A.

      True

    • B.

      False

    Correct Answer
    B. False
    Explanation
    The depositMoney() method declaration has no formal parameter listed, therefore we cannot call the depositMoney() method and pass in a parameter.

    Rate this question:

  • 15. 

    What is the value that is returned in the following method?public static int getVolume() {   int v;   v = 23;   if (v < 50) {      return 50;   }   return v;}

    • A.

      50

    • B.

      23

    • C.

      100

    • D.

      50 and 100

    • E.

      150

    Correct Answer
    A. 50
    Explanation
    The if statement is true so the first return takes place. Once you call return the method is finished and will never perform anything else.

    Rate this question:

Quiz Review Timeline +

Our quizzes are rigorously reviewed, monitored and continuously updated by our expert board to maintain accuracy, relevance, and timeliness.

  • Current Version
  • Jul 11, 2023
    Quiz Edited by
    ProProfs Editorial Team
  • Mar 12, 2011
    Quiz Created by
    Raphord
Back to Top Back to top
Advertisement
×

Wait!
Here's an interesting quiz for you.

We have other quizzes matching your interest.