Quiz 3The signature of a method consists of ________.

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, list[1] is ________. 3.4 undefined 5.5 2.0 3.4

2.0

If you declare an array double[ ] list = {3.4, 2.0, 3.5, 5.5}, the highest index in array list is ________. 3 4 0 2 1

3

Assume int[ ] t = {1, 2, 3, 4}. What is t.length?

4

How many elements are in array double[ ] list = new double[5]?

5

What would be the result of attempting to compile and run the following code? public class Test { public static void main(String[ ] args) { double[ ] x = new double[ ]{1, 2, 3}; System.out.println("Value is " + x[1]); } } The program has a compile error because the syntax new double[ ]{1, 2, 3} is wrong and it should be replaced by new double[3]{1, 2, 3}; The program compiles and runs fine and the output "Value is 2.0" is printed. The program has a compile error because the syntax new double[ ]{1, 2, 3} is wrong and it should be replaced by new double[ ]{1.0, 2.0, 3.0}; The program has a compile error because the syntax new double[ ]{1, 2, 3} is wrong and it should be replaced by {1, 2, 3}. The program compiles and runs fine and the output "Value is 1.0" is printed.

The program compiles and runs fine and the output "Value is 2.0" is printed.

Analyze the following code: public class Test { public static void main(String[ ] args) { int[ ] x = {1, 2, 3, 4}; int[ ] y = x; x = new int[2]; for (int i = 0; i < y.length; i++) System.out.print(y[i] + " "); } }

The program displays 1 2 3 4

Analyze the following code: public class Test { public static void main(String[ ] args) { int[ ] oldList = {1, 2, 3, 4, 5}; reverse(oldList); for (int i = 0; i < oldList.length; i++) System.out.print(oldList[i] + " "); } public static void reverse(int[ ] list) { int[ ] newList = new int[list.length]; for (int i = 0; i < list.length; i++) newList[i] = list[list.length - 1 - i]; list = newList; } }

The program displays 1 2 3 4 5.

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; } }

The program displays int, long followed by 5.

Analyze the following code: class Test { public static void main(String[ ] args) { System.out.println(xmethod(5)); } public static int xmethod(int n, long t) { System.out.println("int"); return n; } public static long xmethod(long n) { System.out.println("long"); return n; } }

The program displays long followed by 5.

Analyze the following code. public class Test { public static void main(String[ ] args) { int[ ] x = new int[3]; System.out.println("x[0] is " + x[0]); } } The program has a compile error because the size of the array wasn't specified when declaring the array. The program runs fine and displays x[0] is 0. The program has a runtime error because the array elements are not initialized. The program has a runtime error because the array element x[0] is not defined.

The program runs fine and displays x[0] is 0.

A variable defined inside a method is referred to as ________.

a local variable

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. a heap an array storage area a stack

a stack

The JVM stores the array in an area of memory, called ________, which is used for dynamic memory allocation where blocks of memory are allocated and freed in an arbitrary order. memory block stack dynamic memory heap

heap

What is k after the following block executes? { int k = 2; nPrint("A message", k); } System.out.println(k);

k is not defined outside the block. So, the program has a compile error

The reverse method is defined in the textbook. What is list1 after executing the following statements? int[ ] list1 = {1, 2, 3, 4, 5, 6}; list1 = reverse(list1);

list1 is 6 5 4 3 2 1

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

method name and parameter list

Arguments to methods always appear within ________. quotation marks parentheses curly braces brackets

parentheses

When you invoke a method with a parameter, the value of the argument is passed to the parameter. This is referred to as ________. pass by value pass by name pass by reference method invocation

pass by value

All Java applications must have a method ________. public static Main(String[ ] args) public static Main(String args[ ]) public static void main(String[ ] args) public static main(String[ ] args) public void main(String[ ] args)

public static void main(String[ ] args)


संबंधित स्टडी सेट्स

Marketing Exam 3 Video Questions

View Set

Principles of Finance - C708 - UNIT 4

View Set

MB 411 Final Exam (all questions and short answer)

View Set

Chapter 14: Communicable and Infectious Disease Risks

View Set

CCNA 1 Chapter 11 Build a Small Network

View Set

Ch 14; Drug Therapy for Treatment of Cancer

View Set