Quiz
Segundo Set de Preguntas Java OCA Exam (1z0-803)
Questions in this quiz (14)
1Which conditional statement would be best suited for determining the flow of code based on an int that may have a value between 1 and 10? The program must react differently for each value.
- Aif-else statement
- Bif-else-if statement with multiple if-elses
- Cmultiple if statements
- Dswitch statement
2What Java code is used for declaring and initializing a null object?
- AObject object = new Object();
- BObject object = new Object(null);
- CObject object = null;
- DObject object = null();
3Given the following code segment, what would be the output?
int value1 = 5;
int value2 = 7;
boolean bool1 = true;
boolean bool2 = false;
if (bool1 && (( value1 < value2 )|| bool2 ) && !(bool2)) {
System.out.println("Result set one");
}
else {
System.out.println("Result set two");
}- AResult set one
- BResult set two
4What is the output for the following Java code segment? The text in parentheses is meant to describe the whitespace and is not part of the output.
String fiveSpaces = " ";
String SCJA = "SCJA";
String lineToDisplay = "fiveSpaces + SCJA + fiveSpaces";
System.out.println(lineToDisplay.trim());- ASCJA (no trailing and leading spaces)
- B SCJA (five leading and trailing spaces)
- C SCJA (four leading and trailing spaces)
- DfiveSpaces + SCJA + fiveSpaces
5Given:
public class StringModifier {
public static void main (String[] args) {
String a = "Supercalifragilisticexpialidocious!";
String b = a.substring(x,y);
char [] c = {a.charAt(u), a.charAt(v)};
System.out.print(b + String.valueOf(c));
}
}
What integer declarations are needed to print the string fragile!?- Aint x = 8; int y = 14; int u = 2; int v =33;
- Bint x = 10; int y = 16; int u = 4; int v =35;
- Cint x = 8; int y = 15; int u = 5; int v =32;
- Dint x = 9; int y = 15; int u = 3; int v =34;
6You want to remove all leading and trailing whitespace from a string.Which method invocation will allow this to occur?
- AstringName.trim();
- BstringName.trim(' ');
- CstringName.trim(" ");
- DstringName.trimWhiteSpace();
7From highest precedence to lowest, which list of operators is ordered properly?
- A*, +, &&, =
- B*, &&, +, =
- C*, =, &&, +
- D+, *, &&, =
8Given the following code that uses the modulus operator, what will be printed? System.out.print((24 % 8) + (10 % 7) + (100 % 99) + (38 % 6));
- A5
- B6
- C0312
- D0302
9Given the following code segment testing the equality of two strings, what will be printed?
1. String string = "Dollar bill";
2. string.replace("Dollar bill","Silver dollar");
3. if ("Dollar bill".equals(string)) {
4. System.out.println ("I have a dollar bill.");
5. } else {
6. System.out.println ("I have a silver dollar.");
7. }- AI have a dollar bill.
- BI have a silver dollar.
- CThe code will not compile because of an error at line 2.
- DThe code will not compile because of an error at line 3.
10Which append declaration does not exist in Java 7?
- Apublic StringBuilder append (short s) {…}
- Bpublic StringBuilder append (int i) {…}
- Cpublic StringBuilder append (long l) {…}
- Dpublic StringBuilder append (float f) {…}
- Epublic StringBuilder append (double d) {…}
11Given:
System.out.println("A" + 1 + (1 + 1) + 1);
What will print?- AA1111
- BA121
- CA13
- DA31
- ECompilation error
12Given:
StringBuilder s = new StringBuilder ("magic");
s.append("al").replace(1, 3, "us").matches("musical");
System.out.println(s);
What will be printed to standard out?- Amagical
- Bmusical
- Ctrue
- DThe code will not compile.
13Given:
boolean value = true;
System.out.print( true || (value=false));
System.out.println(", " + value);
What is printed to standard out?- Atrue, true
- Btrue, false
- Cfalse, true
- Dfalse, false
14Given:
String value1 = "null";
String value2 = "null";
System.out.println(value1.equalsIgnoreCase(value2));
What result will be seen upon compilation and/or execution?- AA NullPointerException is thrown at runtime.
- BequalsIgnoreCase is not a valid method name and causes a compilation error.
- C"true" is printed to standard out.
- D"false" is printed to standard out.
Information
- Description
- Quiz on Segundo Set de Preguntas Java OCA Exam (1z0-803) , created by webmasterMyJavaZone on 18/06/2014.
- Author
- webmasterMyJavaZone
- Language
- Español
- Views
- 33,972
- Tags
- Rating
- 4.0 out of 5 · 1 rating Rate this quiz