Examen1Z0 815
Examen1Z0 815
Given:
public class Test -[
public static void main(String[] args) {
boolean a = new Boolean(Boolean.valueOf (args[0])); boolean b = new
Boolean(args[1]);
System.out.println(a + " " + b);
}
}
And given the commands: javac Test.java java Test TRUE null
What is the result?
A. TRUE null
B. true false
C. false false
D. true true
E. ACIassCastExceptionisthrown at runtime.
A. 4
21
B. 5
4
C. 3
5
D. 4
4
E. 4
7
F. 4
5
Given:
public class MyClass {
public static void main(String[] args) { String s = ”’Java Duke"; int len = s . trim ().
length () ;
System.out.print(len);
}
}
What is the result?
A. Compilation fails
B. 11
C. 8
D. 9
E. 10
Which two options fail to compile when placed at line n1 of the main method?
A. employee.salary = 50_000;
B. director.salary = 80_000;
C. employee.budget = 200_000;
D. manager.budget = 1_000_000;
E. manager.stockOption = 500;
F. director.stockOptions = 1_000;
Which three code fragments can be independently inserted at line nl to enable the
code to print one?
A. Byte x = 1;
B. short x = 1;
C. String x = "1";
D. Long x = 1;
E. Double x = 1;
F. Integer x = new Integer ("1");
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
Which two code fragments, independently, print each element in this array?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
F. Option F
What are the values of each element in intArr after this code has executed?
A. 15, 60, 45, 90, 75
B. 15, 90, 45, 90, 75
C. 15, 30, 75, 60, 90
D. 15, 30, 90, 60, 90
E. 15, 4, 45, 60, 90
A. Option A
B. Option B
C. Option C
D. Option D
Which option represents the state of the num array after successful completion of
the outer loop?
A. Option A
B. Option B
C. Option C
D. Option D
37.- What is the result?
Given:
A. Option A
B. Option B
C. Option C
D. Option D
Which code fragment, when inserted at line n1, enables the code to print Hank?
A. checkAge (iList, ( ) -> p. get Age ( ) > 40);
B. checkAge(iList, Person p -> p.getAge( ) > 40);
C. checkAge (iList, p -> p.getAge ( ) > 40);
D. checkAge(iList, (Person p) -> { p.getAge() > 40; });
Which code fragment, when inserted at line n1, enables the App class to print
Equal?
A. Option A
B. Option B
C. Option C
D. Option D
A. Option A
B. Option B
C. Option C
D. Option D
43.- What is the result?
Given the code fragment:
A. Option A
B. Option B
C. Option C
D. Option D
Which code fragment, when inserted at line 9, enables the code to print true?
A. String str2 = str1;
B. String str2 = new String (str1);
C. String str2 = sb1. toString ();
D. String str2 = "Duke";
Assume that the system date is June 20, 2014. What is the result?
A. Option A
B. Option B
C. Option C
D. Option D
A. Option A
B. Option B
C. Option C
D. Option D
A. Option A
B. Option B
C. Option C
D. Option D
Which code fragment, when inserted at line 3, enables the code to print 10:20?
A. int[] array n= new int[2];
B. int[] array; array = int[2];
C. int array = new int[2];
D. int array [2] ;
Which two modifications, when made independently, enable the code to print
joe:true: 100.0?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
67.- What is the result?
Given the following main method:
Which code fragment, when inserted at line 2, enables the code to compile?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
Which three lines, when inserted independently at line n1, cause the program to
print a o balance?
A. this.amount = 0;
B. amount = 0;
C. acct (0) ;
D. acct.amount = 0;
E. acct. getAmount () = 0;
F. acct.changeAmount(0);
G. acct.changeAmount(-acct.amount);
H. acct.changeAmount(-acct.getAmount());
Which option can replace xxx to enable the code to print 135?
A. int e = 0; e < = 4; e++
B. int e = 0; e < 5; e + = 2
C. int e = 1; e < = 5; e + = 1
D. int e = 1; e < 5; e+ =2
Given:
A. Option A
B. Option B
C. Option C
D. Option D
Which code fragment should you use at line n1 to instantiate the dvd object
successfully?
A. Option A
B. Option B
C. Option C
D. Option D
Which two modifications should you make so that the code compiles successfully?
A. Option A
B. Option B
C. Option C
D. Option D
E. Option E
How should you write methods in the ElectricAccount class at line n1 so that the
member variable bill is always equal to the value of the member variable kwh
multiplied by the member variable rate?
Any amount of electricity used by a customer (represented by an instance of the
customer class) must contribute to the customer’s bill (represented by the member
variable bill) through the method useElectricity method. An instance of the
customer class should never be able to tamper with or decrease the value of the
member variable bill.
A. Option A
B. Option B
C. Option C
D. Option D