Quiz 2

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

What is the output of the following code for (int count = 0; count < 9) System.out.print( count + " " ); count++ ; System.out.println( );

Nothing - won't compile

What is one of the most important difference between arrays and ArrayLists in Java?

The size of an array cannot change. ArrayLists can grow or shrink as needed

What will be printed by the following code snippet, assuming that letters is an initially empty? ---Code--- letters.add("A"); letters.add("B"); letters.add("C"); letters.add(1, "D"); System.out.println(letters.toString());

[A, D, B, C]

Assume that the following method header is for a method in class A. public void displayValue(int value) Assume that the following code segments appear in another method, also in class A. Which contains a legal call to the displayValue method? a: int x = 7; void displayValue(x); b: int x = 7; displayValue(x); c: int x = 7; displayValue(int x); d: int x = 7; x.displayValue();

b: int x = 7; displayValue(x);

class W { static int c = 0; { W w1 = c(); W w2 = c(w1); W w3 = c(w2); W w4 = c(w3); } private W() { System.out.println("c = " + c); } static W c() { return c++ <= 0 ? new W() : null; } static W c(W w) { return w.c++ == 1 ? new W() : null; } }

c = 1 c= 2

Which of the following is valid, given that the following variables are declared: int cost, double taxRate, float interestRate, long count a: interestRate = taxRate; b: cost = taxRate; c: count = cost; d: cost = count;

c: count = cost;

Examine the following code. What will be the output of the following code? public class COmpare { public static void main(String[] args) { Integer i1 = 1; Integer i1 = 1; System.out.println (i1 == i2); Integer i3 = -200; Integer i4 = -200; System.out.println (i3 == i4); } }

true false

How many arguments are passed to the printf method? System.out.printf("Hello %s, the time is %02d:%02d.\n", first + " " + last, hour - 2, minute);

4

If final int SIZE = 15 and int[] x = new int[SIZE], what would be the range of subscript values that could be used with x[]?

0-14

What will be the output of the program: class Output { final static short i = 2; public static int j = 0; for (int k = 0; k < 3; k++) { switch (k) { case i: System.out.print(" 0 "); case i-1: System.out.print(" 1 "); case i-2: System.out.print(" 2 "); } } } }

212012

What is the value of the variable x after the following Java commands are executed, assuming they compile and run without an exception? double x; x = (5 / 4) * Math.abs(-257) + 3.0;

260

Assume that you want to create an array containing ten Die objects. Which of the following code segment accomplishes this correctly? A: ---Code--- Die[] dice = new Die[10]; for (int i = 0; i < dice.length; i++) { dice[i] = new Die(); } B: ---Code--- Die[] dice = new Die[10]; Die die = new Die(); for (int i = 0; i < dice.length; i++) { dice[i] = die; } C: both D: Neither

A: Die[] dice = new Die[10]; for (int i = 0; i < dice.length; i++) { dice[i] = new Die(); }

What will be the output of the following program? public class Time { int a = 50; int b = 10; public static void main(String args[]) { a+ = b--; System.out.println(a); } }

Compilation Error or Runtime Error

Classes with static methods are sometimes referred to as...

Utility Metholds


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

cognitive psychology - final exam part 2

View Set

Financial Management Exam 2 Highfield MSU

View Set

Lewis: MED-SURG: Chapter 25: Burns

View Set