Version User Scope of changes
Sep 14 2007, 1:32 AM EDT (current) rahulrastogi 358 words added, 1936 words deleted
Mar 16 2007, 1:18 AM EDT rahulrastogi 18147 words added, 7 words deleted

Changes

Key:  Additions   Deletions
Basics of Java Programming Which statement is true about a method? Select the one correct answer.a. A method is an implementation of an abstraction. b. A method is an attribute defining the property of a particularabstraction. c. A method is a category of objects. d. A method is an operation defining the behavior for a particular abstraction. e. A method is a blueprint for making operations. Which statement is true about an object? Select the one correct answer. a. An object is what classes are instantiated from. b. An object is an instance of a class.c. An object is a blueprint for creating concrete realization of
abstractions. d. An object is a reference to an attribute. e. An object is a variable. Which line contains a constructor in this class definition?public class Counter //(1){ int current, step;public Counter(int startValue, int stepValue) // (2){ set(startValue);setStepValue(stepValue);} public int get() //(3){ return current; }public void set(int value)//(4) { current = value; } public void setStepValue(int stepValue)//(5) { step = stepValue; } } Select the one correct answer. a. Code marked with (1) is a constructor. b. Code marked with (2) is a constructor. c. Code marked with (3) is a constructor. d. Code marked with (4) is a constructor. e. Code marked with (5) is a constructor. Given that Thing is a class, how many objects and how many reference variables are created by the following code?Thing item, stuff;item = new Thing();Thing entity = new Thing(); Select the two correct answers. a. One object is created. b. Two objects are created. c. Three objects are created. d. One reference variable is created. e. Two reference variables are created. f. Three reference variables are created. Which statement is true about an instance method? Select the one correct answer. a. An instance member is also called a static member. b. An instance member is always a field. c. An instance member is never a method. d. An instance member belongs to an instance, not to the class as a whole. e. An instance member always represents an operation. How do objects pass messages in Java? Select the one correct answer. a. They pass messages by modifying each other's fields. b. They pass messages by modifying the static variables of each other's classes. c. They pass messages by calling each other's instance methods. d. They pass messages by calling static methods of each other's classes Given the following code, which statements are true?class A { int value1;} class B extends A { int value2;} Select the two correct answers. a. Class A extends class B. b. Class B is the superclass of class A. c. Class A inherits from class B. d. Class B is a subclass of class A. e. Objects of class A have a field named value2. f. ObjectsReview of class B have a field named value1. What command in the Java 2 SDK should be used to compile the following code contained in a file called SmallProg.java? public class SmallProg { public static void main(String[] args) { System.out.println("Good luck!"); } }Select the one correct answer. a. java SmallProg b. javac SmallProg c. java SmallProg.java d. javac SmallProg.java e. java SmallProg main What command in the Java 2 SDK should be used to execute the main() method of a class named SmallProg? Select the one correct answer. a. java SmallProg b. javac SmallProg c. java SmallProg.java d. java SmallProg.class e. java SmallProg.main() Language Fundamental
Which of the following is not a legal identifier? Select the one correct answer. a. a2z b. ödipus c. 52pickup d. _class e. ca$h f. total# Which statement is true? Select the one correct answer. a. new and delete are keywords in the Java language. b. try, catch, and thrown are keywords in the Java language. c. static, unsigned, and long are keywords in the Java language. d. exit, class, and while are keywords in the Java language. e. return, goto, and default are keywords in the Java language. f. for, while, and next are keywords in the Java language. Is this a complete and legal comment?/* // */ Select the one correct answer. a. No, the block comment (/* ... */) is not ended since the single-line comment (// ...) comments out the closing part. b. It is a completely valid comment. The // part is ignored by the compiler. c. This combination of comments is illegal and the compiler will reject it. Which of the following do not denote a primitive data value in Java? Select the two correct answers. a. "t" b. 'k' c. 50.5F d. "hello" e. false Which of the following primitive data types are not integer types? Select the three correct answers. a. Type boolean b. Type byte c. Type float d. Type short e. Type double Which integral type in Java has the exact range from -2147483648 (-231) to 2147483647 (231-1), inclusive? Select the one correct answer. a. Type byte b. Type short c. Type int d. Type long e. Type char Which of the following lines are valid declarations?Select the three correct answers. a. char a = '\u0061'; b. char 'a' = 'a'; c. char \u0061 = 'a'; d. ch\u0061r a = 'a'; e. ch'a'r a = 'a'; Given the following code within a method, which statement is true?int a, b;b = 5;Select the one correct answer. a. Local variable a is not declared. b. Local variable b is not declared. c. Local variable a is declared but not initialized. d. Local variable b is declared but not initialized. e. Local variable b is initialized but not declared. In which of these variable declarations will the variable remain uninitialized unless explicitly initialized?Select the one correct answer. a. Declaration of an instance variable of type int. b. Declaration of a static variable of type float. c. Declaration of a local variable of type float. d. Declaration of a static variable of type Object. e. Declaration of an instance variable of type int[]. What will be the result of attempting to compile this class?import java.util.*; package com.acme.toolkit; public class AClass { public Other anInstance;}class Other { int value;}Select the one correct answer. a. The class will fail to compile, since the class Other has not yet been declared when referenced in class AClass. b. The class will fail to compile, since import statements must never be at the very top of a file. c. The class will fail to compile, since the package declaration can never occur after an import statement. d. The class will fail to compile, since the class Other must be defined in a file called Other.java. e. The class will fail to compile, since the class Other must be declared public. f. The class will compile without errors. Is an empty file a valid source file?Answer true or false. Which of these are valid declarations of the main() method in order to start the execution of a Java application?Select the two correct answers. a. static void main(String[] args) { /* ... */ } b. public static int main(String[] args) { /* ... */ } c. public static void main(String args) { /* ... */ } d. final public static void main(String[] arguments) { /* ... */ } e. public int main(Strings[] args, int argc) { /* ... */ } f. static public void main(String args[]) { /* ... */ } Which of the following are reserved keywords?Select the three correct answers. a. public b. static c. void d. main e. String f. args Operator & Assignment
Review of Java Language Basics of Java Programming
1.1
Which statement is true about a method? Select Select the one correct answer.
a. A method is an implementation of an abstraction.
b. A method is an attribute defining the property of a particular abstraction.
c. A method is a category of objects.
d. A method is an operation defining the behavior for a particular abstraction.
e. A method is a blueprint for making operations.
1.2
Which statement is true about an object? Select the one correct answer.
a. An object is what classes are instantiated from.
b. An object is an instance of a class.
c. An object is a blueprint for creating concrete realization of abstractions.
d. An object is a reference to an attribute.
e. An object is a variable.
1.3
Which line contains a constructor in this class definition?
public class Counter { // (1) int current, step; public Counter(int startValue, int stepValue) { // (2) set(startValue); setStepValue(stepValue); } public int get() { return current; } // (3) public void set(int value) { current = value; } // (4) public void setStepValue(int stepValue) { step = stepValue; } // (5)}Select the one correct answer. a. Code marked with (1) is a constructor.
b. Code marked with (2) is a constructor.
c. Code marked with (3) is a constructor.
d. Code marked with (4) is a constructor.
e. Code marked with (5) is a constructor.
1.4
Given that Thing is a class, how many objects and how many reference variables are created by the following code?
Thing item, stuff;item = new Thing();Thing entity = new Thing(); Select the two correct answers.
a. One object is created.
b. Two objects are created.
c. Three objects are created.
d. One reference variable is created.
e. Two reference variables are created.
f. Three reference variables are created.
1.5
Which statement is true about an instance method?
Select the one correct answer.
a. An instance member is also called a static member.
b. An instance member is always a field.
c. An instance member is never a method.
d. An instance member belongs to an instance, not to the class as a whole.
e. An instance member always represents an operation.
1.6
How do objects pass messages in Java?
Select the one correct answer.
a. They pass messages by modifying each other's fields.
b. They pass messages by modifying the static variables of each other's classes.
c. They pass messages by calling each other's instance methods.
d. They pass messages by calling static methods of each other's classes.
1.7
Given the following code, which statements are true?
class A { int value1;}int classvalue1;}class B extends A { int value2;} Select the two correct answers.
a. Class A extends class B. B.
b. Class B is the superclass of class A. A.
c. Class A inherits from class B. B.
d. Class B is a subclass of class A. A.
e. Objects of class A have a field named value2. value2.
f. Objects of class B have a field named value1.value1.
1.8
What command in the Java 2 SDK should be used to compile the following code contained in a file called SmallProg.java? SmallProg.java?
public class SmallProg {
public static void main(String[] args) { System.out.println("Good luck!"); }
}Select the one correct answer.
a. java SmallProg
b. javac SmallProg
c. java SmallProg.java
d. javac SmallProg.java
e. java SmallProg main
1.9
What command in the Java 2 SDK should be used to execute the main() method of a class named SmallProg? SmallProg?
Select the one correct answer.
a. java SmallProg
b. javac SmallProg
c. java SmallProg.java
d. java SmallProg.class
e. java SmallProg.main()

Language Fundamental
2.1
Which of the following is not a legal identifier?
Select the one correct answer.
a. a2z
b. ödipus
c. 52pickup
d. _class
e. ca$h
f. total#
2.2
Which statement is true?
Select the one correct answer.
a. new and delete are keywords in the Java language.
b. try, catch, try, catch, and thrown are keywords in the Java language.
c. static, unsigned, static, unsigned, and long are keywords in the Java language.
d. exit, class, exit, class, and while are keywords in the Java language.
e. return, goto, return, goto, and default are keywords in the Java language.
f. for, while, for, while, and next are keywords in the Java language.
2.3
Is this a complete and legal comment?
/* // */ Select the one correct answer.
a. No, the block comment (/*(/* ... */) is not ended since the single-line comment (// ...)(// ...) comments out the closing part.
b. It is a completely valid comment. The // part is ignored by the compiler.
c. This combination of comments is illegal and the compiler will reject it.
2.4
Which of the following do not denote a primitive data value in Java?
Select the two correct answers.
a. "t"
b. 'k'
c. 50.5F
d. "hello"
e. false
2.5
Which of the following primitive data types are not integer types?
Select the three correct answers.
a. Type boolean
b. Type byte
c. Type float
d. Type short
e. Type double
2.6
Which integral type in Java has the exact range from -2147483648-2147483648 (-231)(-231) to 2147483647 (231-1), (231-1), inclusive?
Select the one correct answer.
a. Type byte
b. Type short
c. Type int
d. Type long
e. Type char
2.7
Which of the following lines are valid declarations?Select the three correct answers. a. char a = '\u0061';
b. char 'a' = 'a';
c. char \u0061 = 'a';
d. ch\u0061r a = 'a';
e. ch'a'r a = 'a';
2.8
Given the following code within a method, which statement is true?int a, b;b = 5;Select the one correct answer. a. Local variable a is not declared.
b. Local variable b is not declared.
c. Local variable a is declared but not initialized.
d. Local variable b is declared but not initialized.
e. Local variable b is initialized but not declared.
2.9
In which of these variable declarations will the variable remain uninitialized unless explicitly initialized?Select the one correct answer. a. Declaration of an instance variable of type int. int.
b. Declaration of a static variable of type float. float.
c. Declaration of a local variable of type float. float.
d. Declaration of a static variable of type Object. Object.
e. Declaration of an instance variable of type int[].int[].
2.10
What will be the result of attempting to compile this class?import java.util.*; package com.acme.toolkit;java.util.*;package publiccom.acme.toolkit;public class AClass { public Other anInstance;}class Other { int value;}Select the one correct answer. a. The class will fail to compile, since the class Other has not yet been declared when referenced in class AClass.
b. The class will fail to compile, since import statements must never be at the very top of a file.
c. The class will fail to compile, since the package declaration can never occur after an import statement.
d. The class will fail to compile, since the class Other must be defined in a file called Other.java.
e. The class will fail to compile, since the class Other must be declared public.
f. The class will compile without errors.
2.11
Is an empty file a valid source file?Answer true or false.
2.12
Which of these are valid declarations of the main() method in order to start the execution of a Java application?Select the two correct answers. a. static void main(String[] args) { /* ... */ }
b. public static int main(String[] args) { /* ... */ }
c. public static void main(String args) { /* ... */ }
d. final public static void main(String[] arguments) { /* ... */ }
e. public int main(Strings[] args, int argc) { /* ... */ }
f. static public void main(String args[]) { /* ... */ }
2.13
Which of the following are reserved keywords?Select the three correct answers. a. public
b. static
c. void
d. main
e. String
f. args


Operator & Assignment
3.1
Given char c = 'A';
What is the simplest way to convert the character value in c into an int? int?
Select the one correct answer.
a. int i = c;
b. int i = (int) c;
c. int i = Character.getNumericValue(c);
3.2
What will be the result of attempting to compile and run the following class?
public class Assignment { public static void main(String[] args) { int a, b, c; b = 10; a = b = c = 20; System.out.println(a); }} Select the one correct answer.
a. The code will fail to compile, since the compiler will recognize that the variable c in the assignment statement a = b = c = 20; has not been initialized.
b. The code will fail to compile because the assignment statement a = b = c = 20; is illegal.
c. The code will compile correctly and will display 10 when run.
d. The code will compile correctly and will display 20 when run.
3.3
What will be the result of attempting to compile and run the following program?
public class MyClass { public static void main(String[] args) { String a, b, c; c = new String("mouse"); a = new String("cat"); b = a; a = new String("dog"); c = b; System.out.println(c); }} Select the one correct answer.
a. The program will fail to compile.
b. The program will print mouse when run.
c. The program will print cat when run.
d. The program will print dog when run.
e. The program will randomly print either cat or dog when run.
3.4
Which of the following expressions will be evaluated using floating-point arithmetic?
Select the three correct answers.
a. 2.0 * 3.0
b. 2 * 3
c. 2/3 + 5/7
d. 2.4 + 1.6
e. 0x10 * 1L * 300.0
3.5
What is the value of the expression (1 / 2 + 3 / 2 + 0.1)? 0.1)?
Select the one correct answer.
a. 1
b. 1.1
c. 1.6
d. 2
e. 2.1
3.6
What will be the result of attempting to compile and run the following program?
public class Integers {
public static void main(String[] args) {
System.out.println(0x10 + 10 + 010);
}
}
Select the one correct answer.
a. The program will not compile. The compiler will complain about the expression 0x10 + 10 + 010. 010.
b. When run, the program will print 28. 28.
c. When run, the program will print 30. 30.
d. When run, the program will print 34. 34.
e. When run, the program will print 36. 36.
f. When run, the program will print 101010.101010.
3.7
Which of the following expressions are valid?
Select the three correct answers.
a. (- 1 -)
b. (+ + 1)
c. (+-+-+-1)
d. (--1)
e. (1 * * 1)
f. (- -1)
3.8
What is the value of evaluating the following expression (-(- -1-3 * 10 / 5-1)? 5-1)?
Select the one correct answer.
a. –8
b. –6
c. 7
d. 8
e. 10
f. None of the above.
3.9
Which of these assignments are valid?
Select the four correct answers.
a. short s = 12;
b. long l = 012;
c. int other = (int) true;
d. float f = -123;
e. double d = 0x12345678;
3.10
Which statements are true?Select the three correct answers. a. The result of the expression (1 + 2 + "3") would be the string "33". "33".
b. The result of the expression ("1" + 2 + 3) would be the string "15". "15".
c. The result of the expression (4 + 1.0f) would be the float value 5.0f. 5.0f.
d. The result of the expression (10/9) would be the int value 1. 1.
e. The result of the expression ('a' + 1) would be the char value 'b'.'b'.
3.11
What happens when you try to compile and run the following program?public class Prog1 { public static void main(String[] args) { int k = 1; int i = ++k + k++ + + k; System.out.println(i); }}Select the one correct answer. a. The program will not compile. The compiler will complain about the expression ++k + k++ + + k. k.
b. The program will compile and will print the value 3 when run.
c. The program will compile and will print the value 4 when run.
d. The program will compile and will print the value 7 when run.
e. The program will compile and will print the value 8 when run.
3.12
Which is the first incorrect line that will cause a compile time error in the following program?public class MyClass { public static void main(String[] args) { char c; int i; c = 'a'; // (1) i = c; // (2) i++; // (3) c = i; // (4) c++; // (5) }}Select the one correct answer. a. The line labeled (1)
b. The line labeled (2)
c. The line labeled (3)
d. The line labeled (4)
e. The line labeled (5)
f. None of the lines are incorrect. The program will compile just fine.
3.13
What happens when you try to compile and run the following program?public class Cast { public static void main(String[] args) { byte b = 128; int i = b; System.out.println(i); }}Select the one correct answer. a. The compiler will refuse to compile it, since you cannot assign a byte to an int without a cast.
b. The program will compile and will print 128 when run.
c. The compiler will refuse to compile it, since 128 is outside the legal range of values for a byte. byte.
d. The program will compile, but will throw a ClassCastException when run.
e. The program will compile and will print 255 when run.
3.14
What will the following program print when run?public class EvaluationOrder { public static void main(String[] args) { int[] array = { 4, 8, 16 }; int i=1; array[++i] = --i; System.out.println(array[0] + array[1] + array[2]); }}Select the one correct answer. a. 13
b. 14
c. 20
d. 21
e. 24
3.15
Which of the following expressions evaluates to true?Select the two correct answers. a. (false | true)
b. (null != null)
c. (4 <= 4)
d. (!true)
e. (true & false)
3.16
Which statements are true?Select the two correct answers. a. The remainder operator % can only be used with integral operands.
b. Identifiers in Java are case insensitive.
c. The arithmetic operators *, /, and % have the same level of precedence.
d. A short value ranges from -128 to +127 inclusive.
e. (+15) is a legal expression.
3.17
Which statements are true about the lines of output printed by the following program?public class BoolOp { static void op(boolean a, boolean b) { boolean c = a != b; boolean d = a ^ b; boolean e = c == d; System.out.println(e); } public static void main(String[] args) { op(false, false); op(true, false); op(false, true); op(true, true); }}Select the three correct answers. a. All lines printed are the same.
b. At least one line contains false.
c. At least one line contains true.
d. The first line contains false.
e. The last line contains true.
3.18
What happens during execution of the following program?public class OperandOrder { public static void main(String[] args) { int i = 0; int[] a = {3,6}; a[i] = i = 9; System.out.println(i + " " + a[0] + " " + a[1]); }}Select the one correct answer. a. Throws an exception of type ArrayIndexOutOfBoundsException
b. Prints "9 9 6"
c. Prints "9 0 6"
d. Prints "9 3 6"
e. Prints "9 3 9"
3.19
Which statements are true about the output of the following program?public class Logic { public static void main(String[] args) { int i = 0; int j = 0; boolean t = true; boolean r; r = (t & 0<(i+=1)); r = (t && 0<(i+=2)); r = (t | 0<(j+=1)); r = (t || 0<(j+=2)); System.out.println(i + " " + j); }}Select the two correct answers. a. The first digit printed is 1.
b. The first digit printed is 2.
c. The first digit printed is 3.
d. The second digit printed is 1.
e. The second digit printed is 2.
f. The second digit printed is 3.
3.20
What would be printed during execution of the following program?
public class MyClass { public static void main(String[] args) { test(1<<32, "1<<32"); test(1<<31, "1<<31"); test(1<<30, "1<<30"); test(1, "1" ); test(0, "0" ); test(-1, "-1" ); } public static void test(int i, String exp) { if ((i >> 1) != (i >>> 1)) System.out.println(exp); }} Select the two correct answers.
a. "1<<32"
b. "1<<31"
c. "1<<30"
d. "1"
e. "0"
f. "-1"
3.21
Which of the following are not operators in Java?
Select the two correct answers.
a. %
b. <<<
c. &
d. %=
e. >>>
f. <=
g. &&=
3.22
Given a variable x of type int (which may contain a negative value), which are correct ways of doubling the value of x,x, barring any wrapping of out-of-range intermediate values?
Select the four correct answers.
a. x << 1;
b. x = x * 2;
c. x *= 2;
d. x += x;
e. x <<= 1;
3.23
Which of the following operators can be used both as an integer bitwise operator and a boolean logical operator?
Select the three correct answers.
a. ^
b. !
c. &
d. |
e. ~
3.24
Given these declarations, which of the following expressions are valid?
byte b = 1;char c = 1;short s = 1;int i = 1; Select the three correct answers.
a. s = b * 2;
b. i = b << s;
c. b <<= s;
d. c = c + b;
e. s += i;
3.25
What will be printed when the following program is run?
public class ParameterPass {
public static void main(String[] args) {
int i = 0;
addTwo(i++);
System.out.println(i);
}

static void addTwo(int i) {
i += 2;
}
}
Select the one correct answer.
a. 0
b. 1
c. 2
d. 3
3.26
What will be the result of attempting to compile and run the following class?
public class Passing {
public static void main(String[] args) {
int a = 0; int b = 0;
int[] bArr = new int[1]; bArr[0] = b; inc1(a);

inc2(bArr); inc1(a); System.out.println("a="inc2(bArr);

System.out.println("a=" + a + " b=" + b + " bArr[0]=" + bArr[0]);
}

public static void inc1(int x) { x++; }

public static void inc2(int[] x) { x[0]++; }
}
Select the one correct answer.
a. The code will fail to compile, since x[0]++; is not a legal statement.
b. The code will compile and will print "a=1 b=1 bArr[0]=1" when run.
c. The code will compile and will print "a=0 b=1 bArr[0]=1" when run.
d. The code will compile and will print "a=0 b=0 bArr[0]=1" when run.
e. The code will compile and will print "a=0 b=0 bArr[0]=0" when run.
3.27
Given the class
// Filename: Args.java
public class Args {
public static void main(String[] args) {
System.out.println(args[0] + " " + args[args.length-1]);
}
}
what would be the result of executing the following on the command line?
java Args In politics stupidity is not a handicap
Select the one correct answer.
a. The program will throw ArrayIndexOutOfBoundsException. ArrayIndexOutOfBoundsException.
b. The program will print "java handicap". handicap".
c. The program will print "Args handicap". handicap".
d. The program will print "In handicap". handicap".
e. The program will print "Args a". a".
f. The program will print "In a".a".
3.28
Which statements would cause a compilation error if inserted in the location indicated in the following program?
public class ParameterUse {
static void main(String[] args) {
int a = 0;
final int b = 1;
int[] c = { 2 };
final int[] d = { 3 };
useArgs(a, b, c, d);
} static void useArgs(final int a, int b, final int[] c, int[] d) {
// INSERT STATEMENT HERE.
}
} Select the two correct answers.
a. a++;
b. b++;
c. b = a;
d. c[0]++;
e. d[0]++;
f. c = d;




Declarations and Access Control
4.1
Given the following declaration, which expression returns the size of the array, assuming the array has been initialized?
int[] array; Select the one correct answer.
a. array[].length()
b. array.length()
c. array[].length
d. array.length
e. array[].size()
f. array.size()
4.2
Is it possible to create arrays of length zero?
Select the one correct answer.
a. Yes, you can create arrays of any type with length zero.
b. Yes, but only for primitive data types.
c. Yes, but only for arrays of object references.
d. No, you cannot create zero-length arrays, but the main() method may be passed a zero-length array of String references when no program arguments are specified.
e. No, it is not possible to create arrays of length zero in Java.
4.3
Which one of the following array declaration statements is not legal?
Select the one correct answer.
a. int []a[] = new int [4][4];
b. int a[][] = new int [4][4];
c. int a[][] = new int [][4];
d. int []a[] = new int [4][];
e. int [][]a = new int [4][4];
4.4
Which of these array declaration statements are not legal?
Select the two correct answers.
a. int[] i[] = { { 1, 2 }, { 1 }, {}, { 1, 2, 3 } };
b. int i[] = new int[2] {1, 2};
c. int i[][] = new int[][] { {1, 2, 3}, {4, 5, 6} };
d. int i[][] = { { 1, 2 }, new int[ 2 ] };
e. int i[4] = { 1, 2, 3, 4 };
4.5
What would be the result of attempting to compile and run the following program?
// Filename: MyClass.javaclass MyClass { public static void main(String[] args) { int size = 20; int[] arr = new int[ size ]; for (int i = 0; i < size; ++i) { System.out.println(arr[i]); } }} Select the one correct answer.
a. The code will fail to compile because the array type int[] is incorrect.
b. The program will compile, but will throw an ArrayIndexOutOfBoundsException when run.
c. The program will compile and run without error, but will produce no output.
d. The program will compile and run without error and will print the numbers 0 through 19.
e. The program will compile and run without error and will print 0 twenty times.
f. The program will compile and run without error and will print null twenty times.
4.6
Given the following program, which statement is true?
class MyClass { public static void main(String[] args) { String[] numbers = { "one", "two", "three", "four" }; if (args.length == 0) { System.out.println("no arguments"); } else { System.out.println(numbers[ args.length ] + " arguments"); } }} Select the one correct answer.
a. The program will fail to compile.
b. The program will throw a NullPointerException when run with zero program arguments.
c. The program will print "no arguments" and "two arguments" when called with zero and three program arguments, respectively.
d. The program will print "no arguments" and "three arguments" when called with zero and three program arguments, respectively.
e. The program will print "no arguments" and "four arguments" when called with zero and three program arguments, respectively.
f. The program will print "one arguments" and "four arguments" when called with zero and three program arguments, respectively.
4.7
What would be the result of trying to compile and run the following program?
public class DefaultValuesTest { int[] ia = new int[1]; boolean b; int i; Object o; public static void main(String[] args) { DefaultValuesTest instance = new DefaultValuesTest(); instance.print(); } public void print() { System.out.println(ia[0] + " " + b + " " + i + " " + o); }} Select the one correct answer.
a. The program will fail to compile because of uninitialized variables.
b. The program will throw a java.lang.NullPointerException when run.
c. The program will print "0"0 false NaN null". null".
d. The program will print "0"0 false 0 null". e. null".
e. The program will print "null"null 0 0 null". null".
f. The program will print "null"null false 0 null".null".
4.8
Which one of these is a valid method declaration?
Select the one correct answer.
a. void method1 { /* ... */ }
b. void method2() { /* ... */ }
c. void method3(void) { /* ... */ }
d. method4() { /* ... */ }
e. method5(void) { /* ... */ }
4.9
Given the following code, which statements can be placed at the indicated position without causing compilation errors?
public class ThisUsage {
int planets;
static int suns;
public void gaze() {
int i;
// ... insert statements here ...
}
}
Select the three correct answers.
a. i = this.planets;
b. i = this.suns;
c. this = new ThisUsage();
d. this.i = 4;
e. this.suns = planets;
4.10
Given the following pairs of method declarations, which statements are true?
void fly(int distance) {}
int fly(int time, int speed) { return time*speed; }
void fall(int time) {}
int fall(int distance) { return distance; }
void glide(int time) {}
void Glide(int time) {}
Select the two correct answers.
a. The first pair of methods will compile correctly and overload the method name fly. fly.
b. The second pair of methods will compile correctly and overload the method name fall. fall.
c. The third pair of methods will compile correctly and overload the method name glide. glide.
d. The second pair of methods will not compile correctly.
e. The third pair of methods will not compile correctly.
4.11
Given a class named Book, Book, which one of these is a valid constructor declaration for the class?
Select the one correct answer.
a. Book(Book b) {}
b. Book Book() {}
c. private final Book() {}
d. void Book() {}
e. public static void Book(String[] args) {}
f. abstract Book() {}
4.12
Which statements are true?
Select the two correct answers.
a. All classes must define a constructor.
b. A constructor can be declared private. private.
c. A constructor can return a value.
d. A constructor must initialize all the fields of a class.
e. A constructor can access the non-static members of a class.
4.13
What will be the result of attempting to compile the following program?
public class MyClass {
long var;
public void MyClass(long param) { var = param; } // (1)
public static void main(String[] args) {
MyClass a, b;
a = new MyClass(); // (2)
b = new MyClass(5); // (3)
}
}
Select the one correct answer.
a. A compilation error will occur at (1), since constructors cannot specify a return value.
b. A compilation error will occur at (2), since the class does not have a default constructor.
c. A compilation error will occur at (3), since the class does not have a constructor which takes one argument of type int. int.
d. The program will compile correctly.
4.14
Given the following class, which of these are valid ways of referring to the class from outside of the package net.basemaster? net.basemaster?
package net.basemaster;

public class Base {