Mock Test 1
Mock Test 1
CT038-3-2-OODJ-L-2
Mock Test
Points: 18/30
1. Given the following code, which expression displays the word "Equal"?
String s1="Java";
String s2="java";
if(expression) {
System.out.println("Equal");
} else {
System.out.println("Not equal");
}*
(0/1 Points)
s1==s2
s1.matchCase(s2)
s1.equalsIgnoreCase(s2)
s1.equals(s2)
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 1/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
list.contains("cat")
list.hasObject("cat")
list.indexOf(1)
list.indexOf(2)
// Line n1
switch (cardVal) {
case 4: case 5: case 6:
case 7: case 8:
System.out.println("Hit");
break;
case 9: case 10: case 11:
System.out.println("Double");
break;
case 15: case 16:
System.out.println("Surrender");
break;
default:
System.out.println("Stand");
}
Which code fragment can be inserted at Line n1, independently, enable to print
Stand? *
(1/1 Points)
int cardVal = 8;
interface Printable {
void print();
}
class Square implements Printable {
public void print() {
System.out.println("Square print");
}
}
class Rectangle implements Printable {
public void print() {
System.out.println("Rectangle print");
}
}
public class Test {
// INSERT CODE HERE
movable.print();
}
}*
(1/1 Points)
void walk() {
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 3/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
5. What will happen when you compile and run the following code?
10
30
31
32
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 4/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
E1
E2
5 10 E1
Compilation fails.
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 5/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
switch (5) {
case 0:
System.out.println("zero");
break;
case 1:
System.out.println("one");
default:
System.out.println("default");
case 2:
System.out.println("two");
}*
(0/1 Points)
one
2 + 4 * 3- 7
(2 + 4) * (3 - 7)
2 + (4 * (3 – 7))
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 6/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
((2 + 4) * 3) - 7)
class Main {
public static void main(String args[]) {
String s = "java2s";
s.replace('a', 'Z').trim().concat("Aa");
s.substring(0, 2);
System.out.println(s);
}
}*
(1/1 Points)
javZ2sAa
jZvZ2sAa
jZvZ2s
java2s
12. Which of the following declares an array that supports two rows and a variable
number of columns? *
(1/1 Points)
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 7/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
13. Given:
Compilation fails.
15. Given:
Writing...
Writing book
Writing code
Compilation fails.
16. Which of the following lines will compile without warning or error? *
(0/1 Points)
char d="d";
float f=3.1415;
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 9/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
int i=34;
byte b=257;
17. Given:
import java.util.ArrayList;
import java.util.List;
public class JavaSETest {
public static void main(String[] args) {
List<Integer> elements = new ArrayList<>();
elements.add(10);
int firstElmnt = elements.get(1);
System.out.println(firstElmnt);
}
}
null
10
18. Which access modifier makes a member available only to classes within the
same package or subclasses? *
(1/1 Points)
private
protected
public
package-private
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 10/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
int i = 5;
int j = 10; *
(1/1 Points)
while(i < j) {}
while(i) {}
while((i = 12)==5) {}
while((i = 12)!=5) {}
20. Given the code fragment:
-1
4
A StringIndexOutOfBoundsException is thrown at runtime.
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 11/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
21. Which of the following lines of code cannot individually replace the //INSERT
CODE HERE line so that the code compiles successfully?
int myArray[5];
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 12/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
23. Given:
class SuperClass {
SuperClass(int x) {
System.out.println("Super");
}
}
public class SubClass extends SuperClass {
SubClass() {
// Line n1
System.out.println("Sub 2");
}
}
Which statement, when inserted at Line n1, enables the code to compile? *
(1/1 Points)
this(10);
super(10);
SuperClass(10);
super.SuperClass (10);
24. Which of the following will return the position of the first letter a where the
string s contains "banana"? *
(1/1 Points)
lastIndexOf(2,s);
s.indexOf('a');
s.charAt(2);
indexOf(s,'v');
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 13/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
Compilation error
5
10
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 14/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
Pen Pencil
Box
Compilation fails.
27. Which of the following statements are correct if they replace the comment line?
System.out.println(i);
System.out.println(sc.i);
System.out.println(Main.i);
System.out.println((Main()).i);
28. What is the result of the following operation?
System.out.println(4^3); *
(0/1 Points)
7
12
64
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 15/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
29. Which of the following statements will compile with syntax or runtime errors if
they replace the comment line?
sc.i = 5;
int j = sc.i;
sc.i = 5.0;
System.out.println(sc.i);
30. What's the output of the following code?
default
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 16/17
10/6/2020 CT038-3-2-OODJ-L-2 Mock Test
case1
case2
Compilation error
This content is created by the owner of the form. The data you submit will be sent to the form owner. Never give out
your password.
https://forms.office.com/Pages/ResponsePage.aspx?id=owPtDy1AM0aozYswiCIlPnKy_4jH5-tDkTVRGyORkGBUNVFEWExNTUJTSzE0QU8w… 17/17