CH. 6 QUIZ QUESTIONS

Réussis tes devoirs et examens dès maintenant avec Quizwiz!

A ___________ method does not return a value. -void -non-void

void

Given the following method: static void nPrint(String message, int n) { while (n > 0) { System.out.print(message); n--; } } What is k after invoking nPrint("A message", k)? int k = 2; nPrint("A message", k);

2 k is not n, k is outside while loop

You should fill in the blank in the following code with ________. public class Test { public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5)); } public static ________ getGrade(double score) { if (score >= 90.0); return 'A'; else if (score >= 80.0); return 'B'; else if (score >= 70.0); return 'C'; else return 'F'; } }

char (non-void)

A variable defined inside a method is referred to as ________. - a global variable - a method variable - a block variable - a local variable

local variable

All Java applications must have a method ________.

public static void main(String[] args)

Which of the following is not an advantage of using methods? -Using methods makes programs run faster. -Using methods makes reusing code easier. -Using methods makes programs easier to read. -Using methods hides detailed implementation from the clients.

-Using methods makes programs run faster

The signature of a method consists of _________. -method name -method name and parameter list -return type, method name, and parameter list -parameter list

-method name and parameter list

Java allows you to declare methods with the same name in a class. This is called _________. -method duplication -method overriding -method overloading -method redeclaration

-method overloading

_______ is a simply but incomplete version of a method - A stub - A main method - A non-main method - A method developed using top-down approach

A stub

Analyze the following code: public class Test { public static void main(String[] args) { System.out.println(xMethod(5, 500L)); } public static int xMethod(int n, long l) { System.out.println("int, long"); return n; } public static long xMethod(long n, long l) { System.out.println("long, long"); return n; } } (A)-The program displays int, long followed by 5 (B)-The program displays long, long followed by 5 (C)-The program runs fine but displays things other than 5 (D)-The program doesnt compile bc the compiler cant distinguish which xmethod to invoke

A- The program displays int, long followed by 5

(int)(Math.random() * (65535 + 1)) returns a random number ___________. A- between 1 and 65536 B- between 1 and 65535 C- between 0 and 65535 D- between 0 and 65536

C - between 0 and 65535

A method can be defined inside a method in Java True or false?

False

You can define two methods in the same class with the same name and parameter list. True or false?

False

You can redeclare the variable if it is declared in the method signature. True or false?

False

Does the return statement in the following method cause compiler errors? public static void main(String[] args) { int max = 0; if (max != 0); System.out.println(max); else return; } Yes or no?

No

Arguments to methods always appear within ____. -brackets -parantheses -curly braces -quotation marks

Parantheses

Analyze the following code: public class Test { public static void main(String[] args) { System.out.println(max(1,2)); } public static double 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; } }

Program can't choose which max method to invoke

______ is to implement one method in the structure chart at a time from the top to the bottom. - Bottom-up approach - Top-down approach - Bottom-up and top-down approach - Stepwise refinement

Top-down approach

A method can be declared with no parameters True or false?

True

Methods can be declared in any order in a class. True or false?

True

The actual parameters of a method must match the formal parameters in type, order, and number. True or false?

True

You must have a return statement in a non-void method. True or false?

True

A variable that is declared inside a method is called ________. - a static - an instance - a local - a global - a class

a local

A variable or a value listed in a call to a method is called ________. - a parameter - an argument - a local variable - a global variable

an argument

You should fill in the blank in the following code with ________. public class Test { public static void main(String[] args) { System.out.print("The grade is " + getGrade(78.5)); System.out.print("\nThe grade is " + getGrade(59.5)); } public static ________ getGrade(double score) { if (score >= 90.0); System.out.println( 'A'); else if (score >= 80.0); System.out.println('B'); else if (score >= 70.0); System.out.println( 'C'); else System.out.println( 'F'); } }

void

A return statement without any value can be used in _________. - a non-void method - void method

void method


Ensembles d'études connexes

BIO TOPIC 10 Cellular Respiration

View Set

Nursing 112 Exam #3 Ch. 16, 26, 32, 34, 36, 37

View Set

Exam 3 Things to Know, Exam 2 Things to Know, Hawkins BIO 111 Exam 1 Things to Know

View Set

American Government Chapters warm ups

View Set

4/10-4/13 Words of Animals (Avenue)

View Set