Java Methods Quiz Questions And Answers

15 Questions | Total Attempts: 4355

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, 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

  • 2. 
    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

  • 3. 
    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

  • 4. 
    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

  • 5. 
    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

  • 6. 
    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

  • 7. 
    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

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

      0

    • B. 

      1

    • C. 

      2

    • D. 

      4

  • 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) {      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

  • 10. 
    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) {

  • 11. 
    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

  • 12. 
    What word is missing below (fill in the [Blank]___).  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 [Blank]__  increaseTemperature(int upper, int lower) {     return upper - lower; }
    • A. 

      Ink

    • B. 

      Int

    • C. 

      Tni

    • D. 

      Ttn

  • 13. 
    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

  • 14. 
    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

  • 15. 
    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

Back to Top Back to top