HW5 - max int num1 double num2...

Info iconThis 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--; } }
Background image of page 1

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

View Full DocumentRight 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
Background image of page 2
Background 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

This note was uploaded on 02/15/2012 for the course COP 3502 taught by Professor Staff during the Spring '12 term at University of Florida.

Page1 / 3

HW5 - max int num1 double num2...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online