HW5 - max int num1 double num2...

Info icon This preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
COP 3502: HW 5 CHAPTER 5 DUE DATE: FEB. 17 AT 4:00 PM 1. Each time a method is invoked, the system stores parameters and local variables in an area of memory, known as ________, which stores elements in last-in first-out fashion. (2 points) A ) storage area B ) a heap C ) a stack D ) an array 2. Which of the following should be declared as a void method? (2 points) A ) A method that converts an uppercase letter to lowercase. B ) A method that prints integers from 1 to 100. C ) A method that returns a random integer from 1 to 100. D ) A method that checks whether current second is an integer from 1 to 100. 3. Given the following method, what is the printout of the method call nPrint('a', 4) ? (5 points) static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n--; } }
Image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
4. Analyze the following piece of code and choose the correct answer. (5 points) public class Test { public static void main(String[ ] args) { System.out.println(max(1, 2)); } public static double max(
Image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: max( int num1, double num2) { System.out.println("max(int, double) is invoked"); if (num1 > num2) return num1; else return num2; } public static double max( double num1, int num2) { System.out.println("max(double, int) is invoked"); if (num1 > num2) return num1; else return num2; } } A) The program cannot compile because the compiler cannot determine which max method should be invoked. B) The program runs and prints 2 followed by "max(double, int)" is invoked. C) The program runs and prints 2 followed by "max(int, double)" is invoked. D) The program cannot compile because you cannot have the print statement in a non-void method. E) The program runs and prints "max(int, double) is invoked" followed by 2. 5. Java allows you to declare methods with the same name in a class. This is called ________. (2 points) A. method overriding B. method overloading C. method duplication D. method re-declaration 6. Explain two advantages of using methods in programming. (4 points)...
View Full Document

{[ snackBarMessage ]}

What students are saying

  • Left Quote Icon

    As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

    Student Picture

    Kiran Temple University Fox School of Business ‘17, Course Hero Intern

  • Left Quote Icon

    I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

    Student Picture

    Dana University of Pennsylvania ‘17, Course Hero Intern

  • Left Quote Icon

    The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

    Student Picture

    Jill Tulane University ‘16, Course Hero Intern