Você está na página 1de 120

1Q

public class LoadData {


2. public static void main(String[] args) {
3. Object dt1 = new Object();
4. double pay[] = new double[10];
5. double rcv[][] = new double[1][10];
6. pay[0] = 1.0;
7. pay[1] = 2.0;
8. pay[2] = 3.0;
9. pay[3] = 4.0;
10. pay[4] = 5.0;
11. pay[5] = 6.0;
12. pay[6] = 7.0;
13. pay[7] = 8.0;
14. pay[8] = 9.0;
15. pay[9] = 10.0;
16. dt1 = pay;
17. rcv = dt1;
18. System.out.println(rcv[1][1]);
19. }
20. }

Compilation fails because of an error at line 5.


B
Compilation fails because of an error at line 16.
C
Compilation fails because of an error at line 17.
D
Compilation succeeds and the program prints "1.0".
E
Compilation succeeds and the program prints "2.0".
F
Compilation succeeds and the program prints the reference location for pay.

2Q

Given:

1. public class GetArray {


2. public static void main(String args[]) {
3. float invt[][];
4. float[] prct, grts[];
5. float[][] sms, hms[];
6.
7.
8.
9. }
10. }
Which three statements should you insert on lines 6, 7, and 8 to allow the class to
compile without errors? (Choose three.)

A
invt = hms;
B
hms = prct;
C
invt = grts;
D
grts = new float[1];
E
hms = new float[2][5];
F
grts = new float[1][4];
G
invt = new float[4][2];

3Q

public class GetAry {


2. public static void main(String [] args) {
3. int [][] holdit = new int[6][];
4. for(int x = 0;x<6;x++) {
5. holdit[x] = new int[3];
6. holdit[x][0] = (x + 0);
7. holdit[x][1] = (x + 1);
8. holdit[x][2] = (x + 2);
9. System.out.println(holdit[x][0]+" "+holdit[x][1]+" "+holdit[x][2]);
10. }
11. }
12. }

Compilation fails because of an error on line 3.


B
Compilation fails because of an error on line 5.
C
Compilation succeeds and the program prints:
111
222
333
444
555
666
D
Compilation succeeds and the program prints:
012
123
234
345
456
567

4Q
Which statement will create an array that stores an array of six integer elements?

A
int[][] x = new int[][6];
B
int[][] x = new int[6][];
C
int[][] x = new int[1][6];
D
int[][] x = {0,1,2,3,4,5,6};
E
int[][] x = { {0,1,2,3,4,5}, {0,2,4,6,8,10} };

5Q
Given:

6. float[] f = new float[4];


7.
What should be inserted on line 7 to iterate through each element and assign a new value?
A
for (int i = 0; i <3; i++) { f[i++]; }
B
for (int i = 1; i <= 4; i++) { f[i++]; }
C
for (int i = 1; i <= 4; i++) { f[i] = (f[i] + .0001f); }
D
for (int i = 0; i <= 3; i++) { f[i] = (f[i] + .0001f); }

6Q

int[][] x = {{1,2,3}, {4,5}};


5. System.out.println(x[2][2] + x[1][1]);
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints "2 4".
C
Compilation succeeds and the program prints "5 1".
D
Compilation succeeds, but the ArrayIndexOutOfBounds exception occurs during
program execution.

7Q
Given:

1. public abstract class Prod {


2. public abstract void prmth1();
3. public static void prmth2() {
4. int mth2 = 30;
5. System.out.println("prmth2 = " + mth2);
6. }
7. public abstract void prmth3();
8. }
What is the result?
A
Compilation succeeds.
B
Compilation fails because of an error on line 1.
C
Compilation fails because of an error on line 3.
D
Compilation fails because of an error on line 7.

8Q

Step.java
1. public class Step {
2. public void raise() {
3. int rs1 = 45;
4. int rs2 = 65;
5. }
6. }

Annual.java
1. public class Annual extends Step {
2. int bonus1 = 20;
3. int bonus2 = 30;
4. private void raise() {
5. int ann1 = bonus1 + rs1;
6. int ann2 = bonus2 + rs2;
7. System.out.println("ann1 is " + ann1);
8. System.out.println("ann2 is " + ann2);
9. }
10. }

Compilation succeeds without failure.


B
An error on line 2 of the Step class causes compilation to fail.
C
An error on line 4 of the Annual class causes compilation to fail.
D
Errors on lines 7 and 8 of the Annual class cause compilation to fail.
E
Errors on lines 3 and 4 of the Step class cause compilation to fail.
9Q
Given:

1. public class MyClass {


2.
3. inv = 5;
4. System.out.println("Inv equals " + inv);
5. }
6. }
The method being declared at line 2 of MyClass should be accessible to members in the
same class, other classes in the same package, and to subclasses of MyClass, but to no
other classes. What should you insert on line 2 to accomplish this?

A
static void pay() {
B
public static void pay() {
C
private static void pay() {
D
protected static void pay() {

10Q
Given:

1. public class Skill {


2. private float wrk1 = 1.103f;
3. protected class Tlnt {
4. static float getWrk() {
5. return wrk1;
6. }
7. }
8. }
What is the result?

A
Compilation succeeds.
B
Compilation fails because of an error on line 2.
C
Compilation fails because of errors on lines 4 and 5.
D
Compilation succeeds, but an exception is received when the program is executed.

11Q
Given:

1. _____ class Gimme {


2. public int hre() {
3. int x = 3;
4. return x;
5. }
6. }
Classes should not be allowed to subclass the Gimme class. What should be inserted in
the blank on line 1 to accomplish this?

A
final
B
public
C
private
D
protected

12Q
CrisPay.java
1. package testdir;
2. public class CrisPay {
3. int telm(int x) {
4. int j = (x * 10);
5. return j;
6. }
7. }

CrisDep.java
1. package testdir;
2. public class CrisDep {
3. public static void main(String [] args) {
4. CrisPay c = new CrisPay();
5. System.out.println(c.telm(3));
6. }
7. }

A
Compilation succeeds and the CrisDep.java program prints "30".
B
Compilation succeeds and the CrisDep.java program prints a blank line.
C
Compilation fails because the CrisDep.java program cannot access the method of the
CrisPay.java program.
D
Compilation fails because the CrisDep.java program does not include an import
statement that will allow access to the CrisPay.java program.

13Q

The SipSop class is declared in the myPackageA package. The PipPop class is declared
in the myPackageB package and is a subclass of the SipSop class. The TipTop class is
declared in the myPackageB package. Which access modifier should be applied to a
member of the SipSop class that will allow it to be accessible to the PipPop class but not
to the TipTop class?

A
public
B
private
C
protected
D
no access modifier

14Q
class HapTec {
2. public void getTec() {
3. System.out.println("HapTec");
4. }
5. }
6.
7. public class CapTec extends HapTec {
8. private void getTec() {
9. System.out.println("CapTec");
10. }
11.
12. public static void main(String [] args) {
13. HapTec ht = new HapTec();
14. CapTec ct = new CapTec();
15. ct.getTec();
16. }
17. }

A
Compilation fails because of an error on line 8.
B
Compilation fails because of an error on line 15.
C
Compilation succeeds and the program prints "CapTec".
D
Compilation succeeds and the program prints "HapTec".

15Q
Which statement about overriding methods is true?

A
A protected method can override a public method.
B
A private method can override a method with no access modifier.
C
A public method can override a method with no access modifier.
D
A method with no access modifier can override a protected method.

16Q
class AClass {
2. final void getCls() {
3. System.out.println("AClass");
4. }
5. }
6.
7. public class TheClass extends AClass {
8. protected void getCls() {
9. System.out.println("TheClass");
10. }
11.
12. public static void main(String [] args) {
13. AClass ac = new AClass();
14. TheClass tc = new TheClass();
15. tc.getCls();
16. }
17. }

A
Compilation fails because of an error on line 2.
B
Compilation fails because of an error on line 8.
C
Compilation succeeds and the program prints "AClass".
D
Compilation succeeds and the program prints "TheClass".

17Q
class WrhCnt {
2. static int x = 10;
3. }
4.
5. public class InvCnt extends WrhCnt {
6. public static void main(String [] args) {
7. WrhCnt wc = new WrhCnt();
8. InvCnt ic = new InvCnt();
9. wc.x = 20;
10. System.out.println("main " + ic.x + " " + wc.x);
11. }
12. }
Compilation fails.
B
Compilation succeeds and the program prints "main 10 10".
C
Compilation succeeds and the program prints "main 10 20".
D
Compilation succeeds and the program prints "main 20 20".

18Q
public class CertOne {
2. static {
3. int x = 15;
4. int y = 20;
5. String z = "hello";
6. }
7.
8. public static void main(String [] args) {
9. System.out.println(x + " " + y + " " + z);
10. }
11. }

A
Compilation fails because of errors on line 2.
B
Compilation fails because of errors on line 9.
C
Compilation succeeds and the program prints "15 20 hello".
D
Compilation succeeds, but an exception occurs during program execution.

19Q
Which modifier should be used when the body of a method is going to be written in a
different language?

A
final
B
native
C
abstract
D
synchronized
20Q
class test2 {
2. ______ test2(int s) {
3. System.out.println("This is test2");
4. }
5. }
6.
7. public class test1 extends test2 {
8. public test1(int s) {
9. super(s);
10. System.out.println("This is test1");
11. }
12. public static void main(String [] args) {
13. test1 t = new test1(3);
14. }
15. }
When inserted in the blank on line 2, which two modifiers will cause a compilation error?
(Choose two.)

A
final
B
public
C
transient
D
protected
E
default (no access modifier)

21Q
Which two modifiers can be used when declaring variables? (Choose two.)

A
static
B
native
C
abstract
D
transient
E
synchronized

22Q
private class JClass {
2. public static void main(String [] args) {
3. int x = 3, y = 5;
4. if (x < y) {
5. System.out.println("x jclass");
6. }
7. else {
8. System.out.println("y jclass");
9. }
10. }
11. }

A
Compilation fails because of an error on line 1.
B
Compilation fails because of an error on line 4.
C
Compilation succeeds and the program prints "x jclass".
D
Compilation succeeds and the program prints "y jclass".
E
Compilation succeeds, but an exception occurs during program execution.

23Q
public class MyClass {
2. public int x;
3. public MyClass(int x) {
4. this.x = x;
5. }
6. class YourClass extends MyClass {
7. public int y;
8. public void main() {
9. System.out.println(x + " & " + y);
10. }
11. }
12. }

A
Compilation fails.
B
Compilation succeeds, but a run-time error occurs.
C
Compilation succeeds and the program prints nothing.
D
Compilation succeeds and the program prints the values of x and y.
E
Compilation succeeds, but an exception is received because of an error on line 3.

24Q
Which statement about using constructors while subclassing is true?

A
If the subclass constructor is overloaded, the superclass constructor must be overloaded
as well.
B
If the superclass constructor is not overridden, the subclass must provide a constructor
that overrides the superclass constructor.
C
If the subclass constructor is overridden with a constructor that takes arguments, the
superclass constructor must include the same argument list.
D
If the superclass constructor is overloaded with a constructor that takes arguments, the
subclass must call the superclass constructor providing the correct arguments.

25Q
class YourClass {
2. public YourClass(String x) {
3. x += "hello";
4. }
5. }
6.
7. public class MyClass extends YourClass {
8. public MyClass(String x) {
9.
10. x += ".";
11. System.out.println(x);
12. }
13.
14. }
What should be inserted on line 9 to allow compilation to succeed?

A
super();
B
super(x);
C
YourClass.super;
D
YourClass.super(x);

26Q

Given:

1. class GlsCls {
2.
3. }
4.
5. public class PlsCls extends GlsCls {
6. public PlsCls(int b) {
7. super(b);
8. }
9. }
Which GlsCls constructor must be inserted on line 2?

A
public GlsCls() {}
B
public GlsCls(b) {}
C
public GlsCls(int b) {}
D
public GlsCls(String b) {}

27Q
class test {
2. public int methodA() {
3. return 4;
4. }
5. }
6. public class testb extends test {
7. public static float methodA(int i) {
8. return 8.0f;
9. }
10. public static void main(String args[]) {
11. System.out.println("The answer is " + methodA(3));
12. }
13. }
What is the result?

A
Compilation fails because of an error on line 7.
B
Compilation fails because of an error on line 11.
C
Compilation succeeds and the program prints "The answer is 3".
D
Compilation succeeds and the program prints "The answer is 4".
E
Compilation succeeds and the program prints "The answer is 8.0".

28Q
Given:

1. class MyClass {
2. public float getNum() {
3. return 1.2f;
4. }
5. }
6. public class YourClass extends MyClass {
7. public ______ getNum() {
8. return 3;
9. }
10. }
What should be entered in the blank on line 7 that will allow compilation to succeed?

29Q
Given:

1. public class RstOr {


2.
3. return ((a * c)/(c + a));
4. }
5. }
What should be inserted on line 2 to allow compilation to succeed?

A
int rstMth(float a, byte c) {
B
long rstMth(float a, byte c) {
C
byte rstMth(float a, byte c) {
D
float rstMth(float a, byte c) {

30Q
class GetIt {
2. public Double hereItIs() {
3. Double x = new Double(5.5);
4. return (x);
5. }
6. }
7.
8. public class TestIt extends GetIt {
9. public Integer hereItIs() {
10. Integer y = new Integer(10);
11. return (y);
12. }
13.
14. public static void main(String [] args) {
15. GetIt g = new GetIt();
16. TestIt t = new TestIt();
17. System.out.println(g.hereItIs() + " " + t.hereItIs());
18. }
19. }

A
Compilation fails.
B
Compilation succeeds and the program prints "10".
C
Compilation succeeds and the program prints "5.5".
D
Compilation succeeds and the program prints "5.5 10".
E
Compilation succeeds and the program prints "10 5.5".

31
Given:

1. public class SeeIt {


2. ______ seeMth(char a, byte b) {
3. return (a + (short)b);
4. }
5. }
What should be inserted in the blank on line 2 to allow compilation to succeed?

A
int
B
byte
C
char
D
short

32
class MyPay {
2. public String getPay() {
3. return "Pay is 4.50";
4. }
5. }
6.
7. public class MyTip extends MyPay {
8. public String getPay() {
9. return "Pay is 6.50";
10. }
11.
12. public static void main(String [] args) {
13. MyTip mt = new MyTip();
14. System.out.println(mt.getPay());
15. }
16. }

A
Compilation fails.
B
Compilation succeeds and the program prints "Pay is 4.50".
C
Compilation succeeds and the program prints "Pay is 6.50".
D
Compilation succeeds, but an exception occurs during program execution.

Which statement about subclass method return types is true?

33Q

A
Any method that overrides a method in the parent class must be declared using the same
return type.
B
Any method that overloads a method in the parent class must be declared using the same
return type.
C
Any method that declares an argument list must declare a return type of the same type as
all arguments in the argument list.
D
Any method that declares an argument list must declare a return type of the same type as
an argument in the argument list.

34Q
Given:

1. public class ClassA {


2. public static void main(String [] args) {
3.
4. switch(x) {
5. default:
6. System.out.println("Here it is.");
7. }
8. }
9. }
The ClassA class can be compiled successfully by inserting one of three possible options
on line 3. When inserted separately, which three will allow compilation to succeed?
(Choose three.)

A
int x = 6;
B
short x = 3;
C
char x = 'y';
D
long x = 354;

35Q
public class Tclass {
2. public static void main(String [] args) {
3. int x = 3;
4. int y = 4;
5. if ( ______ ) {
6. System.out.println("You didn't get it.");
7. }
8. else {
9. System.out.println("You didn't get it.");
10. }
11. }
12. }
Which expression may be inserted in the blank on line 5 to allow compilation to succeed?

A
x=y
B
x &= y
C
x == y
D
x && y

36Q
public class MyClass {
2. public static double getPay(float p) {
3. return (p * 4.2);
4. }
5.
6. public static void main(String [] args) {
7. int y = 10;
8. if ((getPay(2.2) <= y) || (getPay(3.1) <= y))
9. System.out.println("Yes");
10. else
11. System.out.println("No");
12. }
13. }

A
A compilation error occurs on line 2.
B
A compilation error occurs on line 3.
C
A compilation error occurs on line 8.
D
Compilation succeeds and the program prints "No".
E
Compilation succeeds and the program prints "Yes".

37Q
public class SwitchIt {
2. public static void main(String[] args) {
3. int weeb = 1;
4. int woob = 2;
5. System.out.println(getWeebWoob(weeb, woob));
6. }
7.
8. public static int getWeebWoob(int x, int y) {
9. switch (x) {
10. case 1: x = x + y;
11. case 2: x = x + y;
12. }
13. return x;
14. }
15. }

A
Compilation fails because of an error on line 9.
B
Compilation succeeds and the program prints "3".
C
Compilation succeeds and the program prints "5".
D
Compilation fails because of errors on lines 10 and 11.

38Q
public class SpecTurn {
2. public static void main(String[] args) {
3. int p0 = 3;
4. int p1 = 3;
5.
6.
7. case(0):
8. System.out.println("I have it.");
9. break;
10. case(1):
11. System.out.println("You have it.");
12. break;
13. case(2):
14. System.out.println("We have it.");
15. break;
16. default:
17. System.out.println("They have it.");
18. }
19. }
20. }
What should be inserted on line 6 to produce the output "They have it."?

A
switch(p0 | p1) {
B
switch(p0 ! p1) {
C
switch(p0 || p1) {
D
switch(p0 && p1) {

39Q
public class PartPick {
2. public static void main(String[] args) {
3. System.out.println(getMthA(args[0]));
4. }
5.
6. public static String getMthA(String x) {
7. if(x) {
8. x += "'s turn";
9. return x;
10. }
11. else {
12. return x;
13. }
14. }
15. }
Given this command-line invocation line:

java PartPick Rick


What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints "Rick".
C
Compilation succeeds and the program prints nothing.
D
Compilation succeeds and the program prints "Rick's turn".

40Q
public class CamTest {
2. public static void main(String [] args) {
3. String[] y = new String[1];
4. y[0] = args[0];
5. String x = "hello";
6.
7. System.out.println("match");
8. }
9. else {
10. System.out.println("no match");
11. }
12. }
13. }
What should be inserted on line 6 to allow compilation to succeed?

A
if (x & y[0]) {
B
if (x.equals.y[0]) {
C
if (x = y[0].value) {
D
if (x.equals(y[0])) {

41Q
public class SofPln {
2. public static void main(String[] args) {
3. int juju = 10;
4. int wuwu = 20;
5.
6.
7. System.out.println("juju" + "wuwu");
8. }
9. else {
10. System.out.println("ju" + "wu");
11. }
12. }
13. }
Which code, when inserted on line 6, will cause a compilation error?

A
if (juju == wuwu) {
B
if (juju <= wuwu) {
C
if (juju && wuwu) {
D
if (juju != wuwu) {

42Q
Given:

1. public class MyTest {


2. public static void main(String args[]) {
3. int b = 0;
4. while (______) {
5. System.out.println("b is equal to " + b);
6. b++;
7. }
8. }
9. }
What should be entered in the blank on line 4 to allow compilation to succeed?

A
b
B
b(5)
C
b&5
D
b=5
E
b<5

43Q
public class ReClass {
2. public static void main(String [] args) {
3. int x = 0;
4. int y = 0;
5. int hold = 0;
6. System.out.println("This is a test.");
7. do {
8. hold = (--y + x++);
9. System.out.println("hold, y, x = " + hold + ", " + y + ", " + x);
10. } while (x <= 5);
11. }
12. }
What is the result?

A
Compilation fails because of an error on line 8.
B
Compilation fails because of an error on line 10.
C
Compilation succeeds and the last message printed is "hold, y, x = 0, -3, 3".
D
Compilation succeeds and the last message printed is "hold, y, x = -1, -6, 6".

44Q
public class DagRag {
2. public static void main(String [] args) {
3.
4. int [][] x = new int[2][4];
5.
6. for(int y = 0; y < 2; y++) {
7. for(int z = 0; z < 4; z++) {
8. x[y][z] = z;
9. }
10. }
11.
12. dg: for(int g = 0; g < 2; g++) {
13. rg: for(int h = 0; h < 4; h++) {
14. System.out.println(x[g][h]);
15.
16. }
17. System.out.println("The end.");
18.
19. }
20.
21. }
22. }
To allow compilation to succeed, and the output to result in:

0
1
2
3
The end.
What should be inserted on lines 15 and 18 respectively?

A
if(h==3) break rg;
if(g==0) break dg;
B
if(g==3) break rg;
if(h==0) break dg;
C
if(h > 3) break dg;
if(g > 0) break dg;
D
if(h > 3) break dg;
if(g > 0) break rg;

45Q
Which statement about a for loop is true?

A
The first expression in a for loop is the test expression.
B
The second expression in a for loop is the increment expression.
C
The semicolons separating the expressions in a for loop are optional.
D
An infinite loop can be written by omitting the middle expression of a for loop.

46Q
public class SprtOne {
2. public static void main(String [] args) {
3. int moe = 25;
4. while(moe > 10) {
5. if ((moe / 2) > 10) {
6. System.out.println(moe + " - Not there yet");
7. }
8. else {
9. System.out.println(moe + " - it's there");
10. }
11. moe--;
12. }
13. System.out.println(moe + " Finished");
14. }
15. }

47Q
Given:

1. public class GrphIt {


2. public static void main(String[] args) {
3. char c = 'a';
4. while(c = 'a') {
5. c += 'b';
6. System.out.println(c);
7. }
8. }
9. }
What is the result?

A
Compilation fails because of an error on line 3.
B
Compilation fails because of an error on line 4.
C
Compilation succeeds and the program prints "a".
D
Compilation succeeds and the program prints "ab".

48Q
Which statement about the do loop is true?

A
The do loop ends with a curly brace.
B
The while keyword in the do loop is optional.
C
The body of the do loop will execute at least once.
D
The expression of the do loop is tested at the beginning of the loop.

49Q
public class DartCo {
2. public void getDart(int x) {
3. int cnt = 0;
4. do {
5. if (cnt == 0) {
6. System.out.println("Welcome!");
7. }
8. else {
9. System.out.println(x);
10. x++;
11. }
12. cnt++;
13. } while (cnt < 15);
14. }
15.
16. public static void main(String [] args) {
17. DartCo dc = new DartCo();
18. dc.getDart(25);
19. }
20. }
What is the value of x at line 9 when the value of cnt equals 14?

A
10
B
25
C
34
D
38
E
45

50Q
Given:
1. public class TinMan {
2. public static void main(String [] args) {
3. int j = 2, y = 3, z = 10;
4. for (;j < 6;j++) {
5. y = (++y + z);
6. System.out.println(y);
7. }
8. }
9. }
What is the output produced by the program?

A
13
23
33
43
B
13
24
36
49
C
14
25
36
47
D
14
26
39
53

52Q
public class FitLin {
2. public static void main(String [] args) {
3. int x = 1;
4. for(int y = 0; y < 4; y++) {
5. try {
6. if(x > 2) {
7. throw new Exception();
8. }
9. System.out.println(x);
10. x++;
11. }
12. catch (Exception e) {
13. System.out.println("Exception");
14. return;
15. }
16. }
17. System.out.println("The End");
18. }
19. }
What is the result?

A
Compilation fails because of an error on line 7.
B
Compilation fails because of an error on line 12.
C
Compilation succeeds and the program prints:
1
2
Exception
D
Compilation succeeds and the program prints:
1
2
Exception
The End
E
Compilation succeeds and the program prints:
1
2
Exception
Exception
The End

53Q
public class CoProd {
2. static int i = 3;
3. public static void main(String [] args) {
4. try {
5. int c = coMeth();
6. if(c > 0) {
7. throw new Exception();
8. }
9. System.out.println(c);
10. }
11. catch (Exception e) {
12. System.out.println("Got it.");
13. System.exit(0);
14. }
15. finally {
16. System.out.println("At last.");
17. }
18. }
19.
20. public static int coMeth() {
21. i = i + 5;
22. return i;
23. }
24. }
What is the result?

A
Compilation fails because of an error on line 13.
B
Compilation fails because of an error on lines 5 and 7.
C
Compilation succeeds and the program prints:
Got it.
D
Compilation succeeds and the program prints:
8
At last.

54Q
public class MyException {
2. public static void myMethA() throws Exception {
3. System.out.println("myMethA");
4. }
5. public static void myMethB() {
6. System.out.println("myMethB");
7. myMethA();
8. }
9. public static void main(String [] args) {
10. try {
11. myMethB();
12. }
13. catch (Exception e) {
14. System.out.println("exception received");
15. }
16. }
17. }
What is the result?

A
Compilation fails because of an error on line 2.
B
Compilation fails because of an error on line 7.
C
Compilation succeeds and the program prints:
myMethB
myMethA
D
Compilation succeeds and the program prints:
myMethA
myMethB

55Q
public class Gritch {
2.
3. throw new Exception();
4. }
5.
6. public static void main(String [] args) {
7. Gritch g = new Gritch();
8. try {
9. g.methoda();
10. }
11. catch (Exception e) {
12. System.out.println("Caught exception.");
13. }
14. }
15. }
What should be inserted on line 2 to allow compilation to succeed?
A
public void methoda() {
B
public void methoda(Exception e) {
C
public void methoda() throws Exception {
D
public void methoda() extends Exception {

56Q
public class Modge {
2. public static void main(String [] args) {
3. int[] x = {2,6,10};
4. try {
5. for (int y=0; y<3; y++) {
6. System.out.println(x[y]);
7. }
8. }
9. catch (Exception e) {
10. System.out.println("Exception caught");
11. }
12. finally {
13. System.out.println("Ending try");
14. }
15. }
16. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints:
Ending try
C
Compilation succeeds and the program prints:
Exception caught
D
Compilation succeeds and the program prints:
Exception caught
Ending try
E
Compilation succeeds and the program prints:
2
6
10
Ending try

57Q
What is the parent class for the Exception class?

A
java.lang.Error
B
java.lang.Throwable
C
java.lang.InternalError
D
java.lang.RuntimeException

58Q
public class CofBrk {
2. public static void main(String [] args) {
3. try {
4. if (args[0].equals("")) {
5. throw new Exception();
6. }
7. else {
8. System.out.println(args[0]);
9. }
10. }
11. catch (Exception e) {
12. System.out.println("Caught it");
13. }
14. }
15. }
After compiling the program, and executing it using this command-line invocation:

java CofBrk Trigger


What is the result?
A
Compilation fails because of an error on line 3.
B
Compilation fails because of an error on line 11.
C
Compilation succeeds and the program prints "Trigger".
D
Compilation succeeds and the program prints "Caught it".
E
Compilation succeeds, but an IOException occurs during program execution.

59Q
public class Flip {
2. public static void main(String [] args) {
3. int a = Integer.parseInt(args[0]);
4. int b = Integer.parseInt(args[1]);
5. try {
6. int c = (a / b);
7. System.out.println(c);
8. }
9. catch (ArrayIndexOutOfBoundsException e1) {
10. System.out.println("You must enter two integer arguments.");
11. }
12. catch (Exception e) {
13. System.out.println("The second argument cannot be 0.");
14. }
15. finally {
16. System.out.println("Try it again!");
17. }
18. }
19. }
After compiling the program, and executing it using this command-line invocation:

java Flip 50
What is the result?

A
Compilation fails because of an error on line 9.
B
Compilation succeeds and the program prints:
Try it again!
C
Compilation succeeds and the program prints:
25
Try it again!
D
Compilation succeeds and the program prints:
You must enter two integer arguments.
Try it again!

E
Compilation succeeds and the program prints:
The second argument cannot be 0.
Try it again!
F
Compilation succeeds, but an exception occurs during program execution.

60Q
public class Follow {
2. public static void main(String [] args) {
3. String x = new String("ex");
4. try {
5. x = x.concat("i");
6. }
7. catch (Exception e) {
8. x = x.concat("s");
9. }
10. finally {
11. x = x.concat("ts");
12. }
13. }
14. }
What is the value of x at line 13?

61Q
public class Upgrd {
2. public void mth1() throws Exception {
3. throw new Exception();
4. }
5. public void mth2() throws Exception {
6. mth1();
7. }
8. public static void main(String [] args) {
9. Upgrd u = new Upgrd();
10. try {
11. u.mth2();
12. System.out.print("no error - ");
13. }
14. catch (Exception e) {
15. System.out.print("error - ");
16. }
17. finally {
18. System.out.println("finished");
19. }
20. }
21. }

What is the result?

A
Compilation fails because of an error on line 3.
B
Compilation fails because of an error on line 5.
C
Compilation succeeds and the program prints:
finished
D
Compilation succeeds and the program prints:
error - finished
E
Compilation succeeds and the program prints:
no error - finished

62Q
public class Gotcha {
2. public static void main(String [] args) {
3. int[] x = new int[5];
4. try {
5. for (int y = 0; y < 5; y++) {
6. x[y] = y;
7. }
8. }
9. catch (Exception e) {
10. System.out.println("got it");
11. x[0]++;
12. }
13. finally {
14. x[0]++;
15. }
16. x[0]++;
17. }
18. }
What is the value of x[0] at line 17?

63QWhich statement about try statements is true?

A
The finally block executes with or without an exception occurring.
B
The catch block should be declared to catch every possible exception.
C
Separate catch blocks should be declared for every possible exception.
D
The try block must include a throws statement to throw an exception when an error
occurs.

64Q
Given:

1. public class NewGarb {


2. public static Object getIt() {
3. Object rg = new Integer(3);
4. Object dg[][] = new Object[1][2];
5. dg[0][1] = rg;
6. dg[0][0] = rg;
7. rg = null;
8. return rg;
9. }
10. }
Which statement is true?
A
The NewGarb class will not compile.
B
The getIt() method must not be declared as static.
C
The NewGarb class compiles, but an exception is received because dg is not set to null.
D
The rg object is eligible for garbage collection after a call to the getIt() method has
returned.

65Q
public class TipTop {
2. public String tipper() {
3. Object tip = new Object();
4. String[] top = new String[2];
5. top[0] = "this";
6. top[1] = "that";
7. tip = top[1];
8. top[1] = top[0];
9. tip = null;
10. return top[0];
11. }
12. }
When is the object created at line 3 eligible for garbage collection?

A
It is eligible after line 7.
B
It is eligible after line 8.
C
It is eligible after line 9.
D
It is not eligible for garbage collection in this method.

66Q
Given:

1. public class SetFor {


2.
3. public static void main(String [] args) {
4.
5. System.out.println("You will need to use " + c);
6. }
7. }
Which two additions will individually allow compilation to succeed? (Choose two.)

A
"char c;" placed on line 2
B
"char c;" placed on line 4
C
"char c = 'f';" placed on line 2
D
"char c = 'f';" placed on line 4
E
"static char c;" placed on line 2
F
"char c = new char();" placed on line 4

67Q
public class MyClass {
2.
3. static float f;
4.
5. f = 1.3f;
6.
7. return f;
8.
9. }
10.
11. }
Which two changes must be made to allow the MyClass class to compile and run?
(Choose two.)

A
Remove "return f;" from line 7.
B
Remove "static float f;" from line 3.
C
Insert "public static void main(String args[]) {" on line 4.
D
Insert "public static void main(String args[]) {" on line 2.
E
Insert "public static float main(String args[]) {" on line 4.
F
Insert "public static float main(String args[]) {" on line 2.

68Q
2. public static int getThis() {
3. int x = 4;
4. int y = 5 * x;
5. return y;
6. }
7. }
8.
9. public class NetGro extends ToNet {
10. public static void main(String args[]) {
11. int z = getThis();
12. System.out.println("Z = " + z);
13. }
14. }
What should be inserted on line 1 for compilation to succeed?

A
class ToNet {
B
abstract class ToNet {
C
private class ToNet {
D
protected class ToNet {

69QWhich statement about abstract methods is true?

A
Subclasses must overload abstract methods.
B
A concrete subclass must implement abstract methods.
C
Abstract methods can be accessed by all members of the same package without
instantiating the class.
D
Abstract methods can be accessed by all members of the same package, but the class
must be instantiated initially.

70Q
public class RemShw {
2. public static void main(String [] args) {
3. int x;
4. String y;
5. for (int z = 0; z < 4; z++) {
6. y = "paint";
7. System.out.println(y + " " + x);
8. }
9. }
10. }
What is the result?

A
Compilation fails because of an error on line 6.
B
Compilation fails because of an error on line 7.
C
Compilation succeeds and the program prints "paint".
D
Compilation succeeds, but an exception occurs during program execution.

71Q
Given:

1. public class BandCt {


2. private static void String inst = "Hello";
3. public static void main(String [] args) {
4. String stnd = "World";
5. System.out.println(inst + " " + stnd);
6. }
7. }
What is the result?

A
Compilation fails because of an error on line 2.
B
Compilation fails because of an error on line 4.
C
Compilation succeeds and the program prints "Hello World".
D
Compilation succeeds, but an exception occurs during program execution.

72Q
Given:

1. protected class Oratio {


2. public static void main(String [] args) {
3. int s = 40;
4. String z = "The number is ";
5. System.out.println(z + s);
6. }
7. }
What is the result?

A
Compilation fails because of an error on line 1.
B
Compilation fails because of an error on line 5.
C
Compilation succeeds and the program prints "The number is 40".
D
Compilation succeeds, but an exception occurs during program execution.

73Q
2. public class Jigget {
3. public static void main(String [] args) {
4. try {
5. FileOutputStream fos = new FileOutputStream("myfile.txt");
6. ObjectOutputStream oos = new ObjectOutputStream(fos);
7. oos.writeObject("This is myfile.txt");
8. System.out.println("You did it");
9. }
10. catch (FileNotFoundException e1) {
11. System.out.println("File not found.");
12. }
13. catch (IOException e2) {
14. System.out.println("Can't write/read file.");
15. }
16. }
17. }
What should be inserted on line 1 to allow compilation to succeed?

A
import java.io.*;
B
package java.io.*;
C
import java.io.ObjectOutputStream;
D
package java.io.ObjectOutputStream;

74Q
interface Brs {
2. public static final double shn = 3.4;
3. }
4.
5. public class Cndlea {
6. public static void main(String [] args) {
7. float svl = 2f;
8. double end = shn * svl;
9. System.out.println("shn=" + shn + " svl=" + svl + " end=" + end);
10. }
11. }
What is the result?

A
Compilation fails because svl is declared incorrectly.
B
Compilation succeeds and the program prints:
shn=3.4 svl=2.0 end=6.8
C
Compilation succeeds, but an exception occurs during program execution.
D
Compilation fails because the Cndlea class does not implement the Brs interface.

75Q

class Ivy2 {
2.
3. System.out.println("This is it");
4. }
5. }
6.
7. public class Ivy {
8. public static void main(String [] args) {
9. Ivy2.mthIvy();
10. }
11. }
What should be inserted on line 2 to allow compilation to succeed?

A
final void mthIvy() {
B
static void mthIvy() {
C
private static void mthIvy() {
D
protected final void mthIvy() {

76Q
Given:

1. package MyPkg;
2. import java.awt.*;
3. public class PlpFct {
4. public static void main(String [] args) {
5. Frame f = new Frame("MyFrame");
6. f.setSize(130,130);
7. f.setVisible(true);
8. }
9. }
What is the result?

A
Compilation fails because of an error on line 1.
B
Compilation fails because of an error on line 2.
C
Compilation succeeds and an empty frame displays.
D
Compilation succeeds, but an exception occurs during program execution.

77Q
interface Soap {
2. public static final double bbl = 6.5;
3. }
4.
5. public class Clean implements Soap{
6. public static void main(String [] args) {
7. Clean c = new Clean();
8. float drt = 1.3f;
9.
10. System.out.println("end=" + end);
11. }
12. }
What can be inserted on line 9 to allow compilation to succeed?

A
double end = bbl * drt;
B
double end = c.bbl * drt;
C
double end = Soap.bbl * drt;
D
Both A and B are correct.
E
Both B and C are correct. F
Both A and C are correct.
G
A, B, and C are correct.

78Q
Given:

1. public class MyClass {


2. public static void main(String [] args) {
3. String myHouse = args[3];
4. String myStreet = args[2];
5. String myCity = args[1];
6. System.out.println(myHouse + " " + myStreet + " " + myCity);
7. }
8. }
Which command-line invocation will result in no exceptions?

A
java MyClass null
B
java MyClass Southend Brick
C
java MyClass Southend Maple Brick
D
java MyClass Tan Southend Maple Brick
79Q
Given:

1. public class ZigZag {


2. public static void main(String [] args) {
3. System.out.println(args[3] + args[2] + args[0]);
4. }
5. }
Using this command-line invocation:

java ZigZag Zig Zag Zoo Zot


What is the output?
A
ZagZotZig
B
ZotZooZig
C
ZigZagZot
D
ZooZagZig

80Q
Which two statements about command-line arguments are true? (Choose two.)

A
They are stored in an array.
B
They are indexed beginning with 1.
C
They are indexed beginning with 0.
D
They are stored in individual variables created for each argument entered.

81Q
Given:

1. public class cotton {


2. public static void main(String [] args) {
3. String[] st = new String[4];
4. for (int x = 0; x < 4; x++) {
5. st[x] = args[x];
6. System.out.println(st[x]);
7. }
8. }
9. }
Using this command-line invocation:

java cotton blue moon


What is the result?
A
Compilation fails.
B
Compilation succeeds and the program prints nothing.
C
Compilation succeeds and the program prints only:
blue
moon
D
Compilation succeeds, but an exception occurs during program execution. The program
prints:
blue
moon
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException
at cotton.main(cotton.java:5)

82Q
Given:

1. public class test {


2. public static void main(String [] args) {
3. int throw = 3;
4. String catch = "Got it!";
5. System.out.println("Here is the " + throw + ". " + catch);
6. }
7. }
What is the result?

A
Compilation fails with an error on line 5.
B
Compilation fails with errors on lines 3 and 4.
C
Compilation fails with errors on lines 3, 4, and 5.
D
Compilation succeeds, but an exception is received.
E
Compilation succeeds and the program prints "Here is the 3. Got it!"
83Q
Given:

1. public class MyClass {


2. public static void main(String [] args) {
3. String ____ = "Hello";
4. }
5. }
Which variable name should be inserted in the blank on line 3 to allow compilation to
succeed?

A
this
B
byte
C
string
D
strictfp
E
transient

84Q
Given:

1. public class PayDay {


2. public static void main(String [] args) {
3. Object thread = new Object();
4. String get = new String("paid");
5. thread = get;
6. System.out.println(thread);
7. }
8. }
What is the result?

A
Compilation fails because of an error on line 3.
B
Compilation fails because of errors on lines 4 and 5.
C
Compilation succeeds and the program prints "paid".
D
Compilation succeeds, but an exception occurs during program execution.

85Q
Which two are valid identifiers? (Choose two.)

A
a22_7
B
88pay
C
bb^ejf
D
_3abcd4

86Q
Given:

1. public class Lucky {


2. public static void main(String [] args) {
3.
4. System.out.println("that's it");
5. }
6. }
What, inserted on line 3, allows compilation to succeed?

A
int llp*4 = 6;
B
int aju-3 = 6;
C
int 664oe = 6;
D
int $23ab = 6;
87Q
Given:

1. public class Pest {


2. public static void main(String [] args) {
3. int cache = 33;
4. int final = 45;
5. System.out.println(cache + " " + final);
6. }
7. }
What is the result?

A
Compilation fails because of an error on line 3.
B
Compilation fails because of errors on lines 4 and 5.
C
Compilation succeeds and the program prints "33 45".
D
Compilation succeeds, but an exception occurs during program execution.

88Q
Given:

1. public class MyTest {


2. public static void main(String [] args) {
3. char [] x = new char[4];
4. char y = x[3];
5. System.out.println(y);
6. }
7. }
What is the result?

A
Compilation succeeds and the program prints 3.
B
Compilation fails because of an error on line 3.
C
Compilation fails because of an error on line 4.
D
Compilation succeeds and the program prints a blank line.
E
Compilation succeeds and an exception is received when the program executes.
89QGiven:

1. public class SaySo {


2. public static void main(String [] args) {
3. int o = 2;
4. boolean p = true;
5. boolean [] z = new boolean[2];
6. p = z[(o-1)];
7. System.out.println(p);
8. }
9. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints "true".
C
Compilation succeeds and the program prints nothing.
D
Compilation succeeds and the program prints "false".

90Q
public class CoJo {
2. public static void main(String [] args) {
3. String [] b = new String[3];
4. b[0] = "Cow";
5. b[1] = "Duck";
6. b[2] = "Chick";
7. boolean [] c = new boolean[1];
8. for(;c[0];) {
9. System.out.println(b[1]);
10. }
11. System.out.println("Finished.");
12. }
13. }
To allow this output:

Duck
Finished.
Which two changes must be made to the CoJo class? (Choose two.)

A
Change line 8 to: for(;c[1];) {
B
Move line 11 directly below line 9.
C
Change line 8 to: for(;c[0];c[0]=true) {
D
Insert this line of code below line 7: c[0] = true;
E
Insert this line of code below line 9: c[0] = false;

91Q
What is the result?

A
Compilation fails because of an error on line 2.
B
Compilation fails because of an error on line 3.
C
Compilation succeeds and the program prints:
89
D
Compilation succeeds and the program prints:
75.3
E
Compilation succeeds and the program prints:
89
75.3

92QGiven:

1. public class Ref {


2. public static void main(String [] args) {
3. int ball, stick;
4. String rule1, rule2;
5. rule1 = "hit";
6. rule2 = "kick";
7. System.out.println(rule1 + " " + stick + " " + rule2 + " " + ball);
8. }
9. }
What is the result?

A
Compilation succeeds and the program prints "hit kick".
B
Compilation fails because the int variables were not initialized.
C
Compilation succeeds, but an exception occurs during program execution.
D
Compilation fails because line 7 cannot print the String and int variables combined

93Q
Given:

1. public class Turn {


2. public static void main(String [] args) {
3. int [] rec = {3,6,8,2,4};
4. rec[5] = rec[3];
5. System.out.println(rec[5]);
6. }
7. }
What is the result?

A
Compilation fails because of an error on line 4.
B
Compilation fails because of an error on line 5.
C
Compilation succeeds and the program prints "8".
D
Compilation succeeds, but an exception occurs during program execution.

94Q
public class Ill {
2. public static void main(String [] args) {
3. String crup;
4. String vi = "sick";
5. char fl = 'o';
6. String fv;
7. crup = vi;
8. fv = crup;
9. System.out.println(crup);
10. }
11. }
What is the value of crup at line 6?

A
"o"
B
null
C
"sick"
D
The value of crup does not exist because compilation fails.

95Q
Which statement about variables is true?

A
Member variables of type int are not initialized.
B
Objects for all reference types are not initialized.
C
Member variables of type char are initialized to null.
D
Objects for all reference types are initialized to null.
96
Given this value:

\uFFFF
Which two data types can store the value? (Choose two.)

A
byte
B
char
C
short
D
float

97Q
Given this literal value:

1.2
Which data type can store the value?

A
int
B
long
C
float
D
short
E
double

98Q
Which value is a valid float type?
A
0.14
B
0.55f
C
5.42e
D
'3.32'

99Q
Given:

1. public class Sun {


2. public static void main(String [] args) {
3. byte rays = 130;
4. short hot = 32122;
5. System.out.println(rays + " " + hot);
6. }
7. }
What is the result?

A
Compilation fails because of an error on line 3.
B
Compilation fails because of an error on line 4.
C
Compilation succeeds and the program prints "130 32122".
D
Compilation succeeds, but an exception occurs during program execution.

100Q
Given:

1. public class Clickit {


2. public static void main(String [] args) {
3. char move = '\t';
4. char here = 'h';
5. System.out.println(move + " " + here);
6. }
7. }
What is the result?
A
Compilation succeeds and the program prints:
h
B
Compilation succeeds and the program prints:
\t h
C
Compilation succeeds and the program prints:
h
D
Compilation fails because of an error on line 3.
E
Compilation fails because of errors on lines 3 and

101Q
Given:

1. public class Wait {


2. public static void main(String [] args) {
3. String liv = new String("I'm waiting");
4. int u = 91;
5. boolean hex = False;
6. System.out.println(liv + " " + u + " " + hex);
7. }
8. }
What is the result?

A
Compilation fails because of an error on line 3.
B
Compilation fails because of an error on line 5.
C
Compilation succeeds and the program prints "I'm waiting 91 False".
D
Compilation succeeds, but an exception occurs during program execution.

102Q
Given:

1. public class ReTank {


2. public static void main(String args[]) {
3. short blue = 110;
4. short white = 2;
5.
6. }
7. }
Which two can be inserted on line 5 to allow compilation to succeed? (Choose two.)

A
int red = (blue * white);
B
byte red = (blue * white);
C
long red = (blue * white);
D
short red = (blue * white);

103Q
Given:

1. public class TryThis {


2. public static void main(String [] args) {
3. int gab = 16;
4. int gar = 11;
5.
6. System.out.println(fab);
7. }
8. }
What should be inserted on line 5 to allow fab to equal 27?

A
int fab = gab ~ gar;
B
int fab = gab & gar;
C
int fab = gab ^ gar;
D
int fab = gab << gar;

104Q
Given:

1. public class MyClass {


2. public static void main(String [] args) {
3.
4. System.out.println(x);
5. }
6. }
Which two will produce the same results when inserted on line 3? (Choose two.)

A
int x = (~25);
B
int x = (10 | 3);
C
int x = (10 >> 2);
D
int x = (10 & 22);
E
int x = (-3 >>> 1);

105Q
Given:

1. public class juju {


2. public static void main(String [] args) {
3. double z = 0xFFFFFFFC;
4. int i = 0xFFFFFFDF;
5. double x = z * i;
6. System.out.println(x);
7. }
8. }
What is the result?
A
Compilation fails because of an error on line 3.
B
Compilation fails because of an error on line 5.
C
Compilation succeeds and the program prints "-37.0".
D
Compilation succeeds and the program prints "132.0".

106Q
public class Comp {
2. public static void main(String [] args) {
3. int a = 5, b = 6, c = 1, d = 15;
4. int e = a * b;
5.
6. System.out.println(f);
7. if (e == f) {
8. System.out.println("You did it");
9. }
10. else {
11. System.out.println("Sorry");
12. }
13. }
14. }
What should be entered on line 5 that will allow the program to print "You did it"?

A
int f = |d;
B
int f = d >> a;
C
int f = d << c;
D
int f = b && d;

108Q
Given:

1. public class Clip {


2. public static void main(String [] args) {
3. int zeb = 3;
4. int jeb = 50;
5. int zj = jeb >>> zeb;
6. System.out.println(zj);
7. }
8. }
Which group of statements can replace lines 3, 4, and 5 and produce the same results?

A
int zeb = 2;
int jeb = 27;
int zj = jeb & zeb;
B
int zeb = 2;
int jeb = 27;
int zj = jeb ^ zeb;
C
int zeb = 2;
int jeb = 27;
int zj = jeb | zeb;
D
int zeb = 2;
int jeb = 27;
int zj = jeb >> zeb;

108Q
public class Vact {
2. public static Vact getVact() {
3. Vact x = new Vact();
4. return x;
5. }
6. public static void main(String [] args) {
7. Object[] o = new Object[2];
8. o[0] = getVact();
9. boolean y = o[1] instanceof Vact;
10. System.out.println(y);
11. }
12. }
What is the result?
A
Compilation fails because of an error on line 9.
B
Compilation succeeds and the program prints "true".
C
Compilation succeeds and the program prints "false".
D
Compilation fails because of errors on lines 7 and 8.

109Q
Which statement about the instanceof operator is true?

A
It returns false if a left operand does not exist.
B
It returns false if a right operand does not exist.
C
It cannot be used with primitive types and values.
D
It cannot be used with array and object types and values.

110Q
public class Hur {
2. public static void main(String [] args) {
3. int x = 352;
4. int y = 439;
5. boolean z;
6. if (y != x) {
7. z = false;
8. }
9. else {
10. z = true;
11. }
12. System.out.println(z);
13. }
14. }
What is the output?

111Q
Given:
1. public class test {
2. public static void main(String [] args) {
3. int x = 323;
4. float y = (float)x;
5. System.out.println(y);
6. }
7. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints:
323.0
C
Compilation succeeds and the program prints nothing.
D
Compilation succeeds, but an exception occurs during program execution.

112Q
public class DetMan {
2. static Object nev = new Object();
3. public static void main(String [] args) {
4. Object lim = new Object();
5. lim = nev;
6. if(nev.equals.lim) {
7. System.out.println("One");
8. }
9. else {
10. System.out.println("Two");
11. }
12. }
13. }
What is the result?

A
Compilation fails because of an error on line 2.
B
Compilation fails because of an error on line 6.
C
Compilation succeeds and the program prints "Two".
D
Compilation succeeds and the program prints "One".

113Q
public class PuNch {
2. public static void main(String [] args) {
3. Object pop = new Object();
4. String bam = new String("Loud");
5. String pow = new String("Soft");
6. pop = pow;
7. bam = "Soft";
8. pop = bam;
9.
10. System.out.println("You got it.");
11. }
12. else {
13. System.out.println("Sorry.");
14. }
15. }
What should be inserted on line 9 to test whether the objects referred to by bam and pow
contain the same data?

A
if(bam = pow) {
B
if(bam == pow) {
C
if(bam.equals.pow) {
D
if(bam.equals(pow)) {

114Q
public class Zurg {
2. public static void main(String [] args) {
3. Object bl = new Object();
4. Object sr = new String("Infinity");
5. Object wd = sr;
6. bl = sr;
7. if (wd.equals(bl)) {
8. System.out.println("Beyond");
9. }
10. else {
11. System.out.println("Ion");
12. }
13. System.out.println(sr);
14. }
15. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints:
Infinity
C
Compilation succeeds and the program prints:
Ion
Infinity
D
Compilation succeeds and the program prints:
Beyond
Infinity

115Q
public class Tree {
2. public static void main(String [] args) {
3. double a = 5.4;
4. double b = 6.7;
5. Double x = new Double(b);
6. Double y = new Double(a);
7.
8.
9. }
10. }
Which two can be inserted on lines 7 and 8 to allow compilation to succeed? (Choose
two.)
A
if (a = b) { System.out.println("a = b"); }
B
if (a == y) { System.out.println("a == y"); }
C
if (a == b) { System.out.println("a == b"); }
D
if (b.equals(x)) { System.out.println("b.equals(x)"); }
E
if (x.equals(y)) { System.out.println("x.equals(y)"); }
F
if (x.equals.(a)) { System.out.println("x.equals.(a)"); }

116Q
public class TexMex {
2. public static void main(String [] args) {
3. String tex = new String("Hot");
4. String z = new String("Spicy");
5. String mex = new String(z);
6. String p = tex;
7. if (tex.equals(mex)) {
8. System.out.println(z);
9. }
10. else {
11. System.out.println(p + "n" + z);
12. }
13. }
14. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints "Spicy".
C
Compilation succeeds and the program prints "HotnSpicy".
D
Compilation succeeds, but an exception occurs during program execution.

117Q
public class Blue {
2. public static void main(String [] args) {
3. Object j = new Object();
4. Boolean b = new Boolean(false);
5. Boolean c = new Boolean(true);
6. j = c;
7. c = b;
8. if (j.equals(b)) {
9. System.out.println("true");
10. }
11. else {
12. System.out.println("false");
13. }
14. }
15. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints "true".
C
Compilation succeeds and the program prints nothing.
D
Compilation succeeds and the program prints "false".

118Q
public class TeSet {
2. public static void main(String args[]) {
3. int m = 2;
4. int p = 1;
5. int t = 0;
6. for(;p < 5;p++) {
7. if(t++ > m) {
8. m = p + t;
9. }
10. }
11. System.out.println("t equals " + t);
12. }
13. }
What is the resulting value of t?
A
2
B
4
C
6
D
7

119Q
public class Lept {
2. public static void main(String [] args) {
3. int a = 320;
4. int b = 4;
5. if ((a & b) == (a | b)) {
6. System.out.println(a & b);
7. }
8. else {
9. System.out.println(a | b);
10. }
11. }
12. }
What is the result?

A
Compilation fails because of an error on line 5.
B
Compilation succeeds and the program prints "0".
C
Compilation succeeds and the program prints "324".
D
Compilation succeeds, but an exception occurs during program execution.

120Q
Given:

1. public class Crunch {


2. public static void main(String [] args) {
3. boolean j = true;
4. boolean k = false;
5. System.out.println((j && k) + " " + (j || k));
6. }
7. }
What is the result?

A
Compilation succeeds and the program prints:
true true
B
Compilation succeeds and the program prints:
true false
C
Compilation succeeds and the program prints:
false true
D
Compilation succeeds and the program prints:
false false

121Q
Given:

1. public class Spot {


2. public static void main(String [] args) {
3. int zoo = 40; // = 00101000 binary
4. int koo = 49; // = 00110001 binary
5. System.out.println(____);
6. }
7. }
What should be inserted in the blank on line 5 to produce the output of 57?

A
zoo | koo
B
zoo & koo
C
zoo ^ koo
D
zoo >> koo

122Q
Given:

1. public class Shade {


2. public static void main(String [] args) {
3. Shade s = new Shade();
4. s.dark(40);
5. }
6. public void dark(int i) {
7. System.out.println(i & 52);
8. }
9. }
What is the result?

A
Compilation fails because of an error on line 4.
B
Compilation fails because of an error on line 7.
C
Compilation succeeds and the program prints "32".
D
Compilation succeeds and the program prints nothing.

123Q
Which statement about the || operator is true?

A
It performs a bitwise OR.
B
It performs a boolean OR.
C
It performs a bitwise AND.
D
It performs a boolean AND.
124Q
public class TrFor {
2. public static void main(String [] args) {
3. int star1 = 4;
4. int star2 = 10;
5. trMeth(star1, star2);
6. System.out.println(star1 + " " + star2);
7. }
8.
9. public static void trMeth(int hold1, int hold2) {
10. hold1 = hold2 * 20;
11. }
12. }
What is the result?

A
Compilation fails because of an error on line 5.
B
Compilation fails because of an error on line 9.
C
Compilation succeeds and the program prints "4 10".
D
Compilation succeeds and the program prints "80 200".

125Q
public class OldGame {
2. public static void main(String [] args) {
3. StringBuffer word1 = new StringBuffer("tic");
4. String word2 = new String("tac");
5. chgIt1(word1);
6. chgIt2(word2);
7. System.out.println(word1+word2);
8. }
9.
10. static void chgIt2(String hold2) {
11. hold2 += "toe";
12. }
13.
14. static void chgIt1(StringBuffer hold1) {
15. StringBuffer hold3 = new StringBuffer("toe");
16. hold1.append(hold3);
17. }
18. }
What will the program produce as output?

126Q
public class MyName2 {
2. public static void getName() {
3. String holdit = "My name is ";
4. }
5.
6. public static void main(String args[]) {
7. String fname = new String(args[0]);
8. String lname = new String(args[1]);
9. String whole = new String();
10. whole = whole.concat(getName()).concat(fname).concat(" ");
11. whole = whole.concat(lname).concat(".");
12. System.out.println(whole);
13. }
14. }
java MyName2 John Smith
What is the result?

A
Compilation fails because of an error on line 3.
B
Compilation fails because of an error on line 10.
C
Compilation succeeds and the program prints "My".
D
Compilation succeeds and the program prints "My is John Smith."
E
Compilation succeeds and the program prints "My name is John Smith."

127Q
public class Roses {
2. public float getPink() {
3. double j = 5.43;
4. return (j + 3.3);
5. }
6. public static void main(String [] args) {
7. Roses r = new Roses();
8. System.out.println(r.getPink());
9. }
10. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints ".73".
C
Compilation succeeds and the program prints "8.73".
D
Compilation succeeds and the program prints nothing.

128Q
public class Wht {
2. public String getWht(String a) {
3. a = a.concat("plus");
4. return a;
5. }
6.
7. public static void main(String [] args) {
8. Wht w = new Wht();
9. System.out.println(w.getWht("A "));
10. }
11. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints:
A
C
Compilation succeeds and the program prints:
A plus
D
Compilation succeeds, but an exception occurs during program execution.

129Q
public class Pan {
2. public static void main(String [] args) {
3. Pan p = new Pan();
4. StringBuffer z = new StringBuffer("bird");
5. p.getPan(z);
6. System.out.println(z);
7. }
8.
9. public void getPan(StringBuffer a) {
10. StringBuffer b = new StringBuffer("ie");
11. a.append(b);
12. }
13. }

What is the output?

130Q
public class Mt {
2. public String getMt(String a) {
3. a += " is here";
4. return a;
5. }
6.
7. public static void main(String [] args) {
8. Mt m = new Mt();
9. System.out.println(m.getMt(args[1]));
10. }
11. }
Using this command-line invocation:

java Mt Reid
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints:
Reid
C
Compilation succeeds and the program prints:
Reid is here
D
Compilation succeeds and the program prints nothing.
E
Compilation succeeds, but an exception occurs during program execution.

131Q
public class Green {
2. public static StringBuffer sb = new StringBuffer("yellow");
3. public static String s = new String();
4.
5. public static void main(String [] args) {
6. Green g = new Green();
7. g.shock();
8. System.out.println(g.sb);
9. System.out.println(g.s);
10. }
11.
12. public void shock() {
13. s = "blue";
14. sb.append("ish");
15. s = s.concat("ish");
16. }
17. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints nothing.
C
Compilation succeeds and the program prints:
yellowish
D
Compilation succeeds and the program prints:
yellowish
blueish

132Q
public class Letr {
2. public int getit(int x) {
3. x = x * 45;
4. return x;
5. }
6.
7. public static void main(String [] args) {
8. Letr l = new Letr();
9.
10. System.out.println(j);
11. }
12. }
What should be inserted on line 9 to allow compilation to succeed and produce the output
"1620"?

A
getit(36);
B
l.getit(36);
C
int j = getit(36);
D
int j = l.getit(36);

133Q
public class Chld {
2. public static int x;
3. public void getChld(int x) {
4. x += 6;
5. }
6.
7. public static void main(String [] args) {
8. Chld ch = new Chld();
9. ch.getChld(59);
10. System.out.println(x);
11. }
12. }
What is the result?
A
Compilation fails.
B
Compilation succeeds and the program prints "0".
C
Compilation succeeds and the program prints "59".
D
Compilation succeeds and the program prints "65".

134Q
public class pcdi {
2.
3. public static void main(String [] args) {
4. pcdi p = new pcdi();
5. char b = 'b';
6. p.pc(b);
7. }
8.
9. public void pc(char a) {
10. System.out.println(a);
11. }
12. }
What is the result?

A
Compilation fails because of an error on line 5.
B
Compilation fails because of an error on line 6.
C
Compilation fails because of an error on line 9.
D
Compilation succeeds and the program prints "b".

135Q
Which two demonstrate the "has a" relationship? (Choose two.)
A
public class Student {}
public class Freshman extends Student {}
B
public interface Movie {}
public class Theatre { private Movie movie }
C
public interface Building {}
public interface Skyscraper extends Building {}
D
public class Student {
private Course theCourse;
public Course getCourse() {
return theCourse;
}
}

136Q
Which statement about encapsulation is true?

A
It requires all methods to be overridden.
B
It allows other classes to use all fields in the class.
C
It provides access to all fields and methods in the class.
D
It keeps fields protected from accidental changes.

137Q
Which statement about the "has a" relationship is true?

A
It is represented by interfaces that extend interfaces.
B
It is represented by classes that implement interfaces.
C
It is represented by objects that extend other objects.
D
It is represented by objects that contain other objects.

138Q
When member data is declared with a private access modifier, what does this represent?

A
immutability
B
encapsulation
C
synchronization
D
the "is a" relationship

139Q
Which two demonstrate the "is a" relationship? (Choose two.)

A
public interface Green {}
public class Color {}
B
public interface Cup {}
public class Glass { private Cup cup; }
C
public interface Vehicle {}
public class Suv implements Vehicle {}
D
public interface Building {}
public interface House extends Building {}

140Q
Which statement about classes demonstrating the "is a" relationship is true?
A
They override no methods from the parent.
B
They override every method from the parent.
C
They do not inherit constructors from the parent.
D
They do not inherit methods and variables from the parent.

141Q
class IntType {
2. public String getType(String a, int b, char c) {
3. String holdit1 = new String();
4. holdit1 = a;
5. return holdit1;
6. }
7. }
8.
9. class OverType extends IntType {
10.
11. String holdit2 = new String();
12. holdit2 = holdit2.concat("This is ").concat(a);
13. return holdit2;
14. }
15.
16. public static void main(String args[]) {
17. OverType ot = new OverType();
18. String x = new String("x");
19. int y = 1;
20. char z = 'b';
21. System.out.println(ot.getType(x, y, z));
22. }
23. }
When inserted on line 10, which line will override the getType method and allow
compilation to succeed?

A
public Char getType(String a, int b, char c) {
B
public Char getType(int b, String a, char c) {
C
public String getType(String a, int b, char c) {
D
public String getType(int b, String a, char c) {

142Q
class GrphSet {
2. public int getGrph(int x) {
3. return 432;
7. }
8. }
9.
10. class TreeSet extends GrphSet {
11. public long getGrph(int x) {
12. return 559;
13. }
14.
15. public static void main(String [] args) {
16. TreeSet tree = new TreeSet();
17. System.out.println(tree.getGrph(30));
18. }
19. }
What is the result?

A
Compilation fails because of an error on line 11.
B
Compilation fails because of an error on line 14.
C
Compilation succeeds and the program prints "559".
D
Compilation succeeds and the program prints "432".

143Q
public class AClass {
2. public static int aNum(int hold1, int hold2) {
3. hold1 = ((hold1 * 5) + hold2);
4. return hold1;
5. }
6.
7. public static int aNum(int hold1) {
8. hold1 = (hold1 * 5);
9. return hold1;
10. }
11.
12. public static void main(String [] args) {
13. int x1 = 1;
14. int x2 = 5;
15. System.out.println(aNum(x1, x2));
16. }
17. }
What is the result?

A
Compilation fails because of an error on line 2.
B
Compilation fails because of an error on line 15.
C
Compilation succeeds and the program prints "5".
D
Compilation succeeds and the program prints "10".

144Q
class AndBit {
2. public static String getBit(String a, int b, char c) {
3. String n = new String();
4. n = n.concat(a).concat(" got it");
5. return n;
6. }
7. }
8.
9. class OrBit extends AndBit {
10. public static int getBit(int b, String a, char c) {
11. int m = b * 3;
12. return m;
13. }
14.
15. public static void main(String [] args) {
16. String y = new String("You");
17. int x = 2;
18. char z = 'b';
19.
20. }
21. }
When inserted on line 19, which line will produce the output of "You got it"?

A
System.out.println(getBit(x));
B
System.out.println(getBit(y));
C
System.out.println(getBit(x, y, z));
D
System.out.println(getBit(y, x, z));

145Q
1. public class Home {
2. public void keepit(int x, int y) {
3. x = x * y;
4. System.out.println(x);
5. }
6.
7. public void keepit(int x, int y, int z) {
8. x = (x * y) + z;
9. System.out.println(x);
10. }
11.
12. public static void main(String [] args) {
13. Home h = new Home();
14. int a = 20;
15. int b = a + 4;
16. int c = b / 2;
17. if (c > 10) {
18. h.keepit(a, b, c);
19. }
20. else {
21. h.keepit(a, b);
22. }
23. }
24. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program executes the method at line 2.
C
Compilation succeeds and the program executes the method at line 7.
D
Compilation succeeds, but an exception occurs during program execution.

146Q
class Tip {
2. public void getTip(String a) {
3. a += "Hello";
4. System.out.println(a);
5. }
6. }
7.
8. public class Top extends Tip {
9. public String getTip(String a) {
10. a = "Hi";
11. System.out.println(a);
12. }
13.
14. public static void main(String [] args) {
15. Top t = new Top();
16. String z = "Bye";
17. t.getTip(z);
18. }
19. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints "ByeHi".
C
Compilation succeeds and the program prints "ByeHello".
D
Compilation succeeds, but an exception occurs during program execution.

147Q
Given:

1. public class Snake {


2. public String tiger(String a) { return a; }
3. }
Which two might form legal overloads of the tiger method? (Choose two.)

A
public char tiger(String a) { return a; }
B
public String tiger(String b) { return b; }
C
public String tiger(String a, int b) { return a; }
D
public int tiger(String a, int b, int c) { return b; }

148Q
Given:

1. class Frog {
2. public Double toad(Double a) { return a; }
3. }
Which method overrides the toad method?

A
4. public class Frogger extends Frog {
5. public Float toad(Float a) { return a; }
6. }
B
4. public class Frogger extends Frog {
5. public Double toad(Double a) { return a; }
6. }
C
4. public class Frogger extends Frog {
5. public Float toad(Double a, Float b) { return a; }
6. }
D
4. public class Frogger extends Frog {
5. public Double toad(Double a, Double b) { return a; }
6. }

149Q
Which statement about overriding methods is true?

A
The argument list must match the original.
B
The return type can differ from the original.
C
The method name can differ from the original.
D
The argument list must differ from the original.

150Q
Which statement about overloading methods is true?

A
The return type must match the original.
B
The argument list must match the original.
C
The method name can differ from the original.
D
The argument list must differ from the original.
151Q
What is a proper method for declaring inner classes?

A
public class MyClass {}
static class YourClass {}
B
public class MyClass {
static class YourClass {}
}
C
public class MyClass {}
static class YourClass extends MyClass {}
D
public class MyClass {
static class YourClass { Object x = new Object(MyClass); }
}

152Q
public class Home {
2. public void keepit(int x, int y) {
3. x = x * y;
4. System.out.println(x);
5. }
6.
7. public void keepit(int x, int y, int z) {
8. x = (x * y) + z;
9. System.out.println(x);
10. }
11.
12. public static void main(String [] args) {
13. Home h = new Home();
14. int a = 20;
15. int b = a + 4;
16. int c = b / 2;
17. if (c > 10) {
18. h.keepit(a, b, c);
19. }
20. else {
21. h.keepit(a, b);
22. }
23. }
24. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program executes the method at line 2.
C
Compilation succeeds and the program executes the method at line 7.
D
Compilation succeeds, but an exception occurs during program execution.

153Q
class Tip {
2. public void getTip(String a) {
3. a += "Hello";
4. System.out.println(a);
5. }
6. }
7.
8. public class Top extends Tip {
9. public String getTip(String a) {
10. a = "Hi";
11. System.out.println(a);
12. }
13.
14. public static void main(String [] args) {
15. Top t = new Top();
16. String z = "Bye";
17. t.getTip(z);
18. }
19. }

A
Compilation fails.
B
Compilation succeeds and the program prints "ByeHi".
C
Compilation succeeds and the program prints "ByeHello".
D
Compilation succeeds, but an exception occurs during program execution.
154Q
What is a proper method for declaring inner classes?

A
public class MyClass {}
static class YourClass {}
B
public class MyClass {
static class YourClass {}
}
C
public class MyClass {}
static class YourClass extends MyClass {}
D
public class MyClass {
static class YourClass { Object x = new Object(MyClass); }
}

155Q
public class TheClass {
2. static int x = 3;
3. public static void main(String [] args){
4. x += OtrClass.x;
5. System.out.println(x);
6. }
7.
8. static class OtrClass {
9. static int x = TheClass.x + 4;
10. }
11. }
What is the result?

A
Compilation fails because of an error on line 4.
B
Compilation fails because of an error on line 9.
C
Compilation succeeds and the program prints "7".
D
Compilation succeeds and the program prints "10".

156Q
Given:

1. public class ThisClass {


2. private String mine = new String("mine");
3. public class ThatClass {
4. public void yourMeth() {
5. //method body
6. }
7. }
8. }
What should you use to instantiate ThatClass from outside its containing class?

A
ThatClass tc = new ThisClass.ThatClass();
B
ThatClass tc = ThatClass.new ThatClass();
C
ThisClass tc = new ThisClass();
ThisClass.ThatClass thc = tc.new ThatClass();
D
ThisClass tc = tc.new ThisClass();
tc.ThatClass thc = new tc.ThatClass();

157Q
Which statement about anonymous classes is true?

A
An interface can be defined anonymously.
B
An anonymous class can define static methods.
C
An anonymous class can declare static final constants.
D
A constructor for an anonymous class is defined using the same name as the containing
class.

158Q
Given:

1. public class MyClass {


2. public static class YourClass {}
3. }
Which statement will construct an instance of the YourClass class from a separate class?

A
YourClass yc = new YourClass();
B
MyClass mc = new MyClass(YourClass());
C
MyClass.YourClass yc = new MyClass.YourClass();
D
MyClass mc = new MyClass();
mc.YourClass yc = new mc.YourClass();

159Q
Which statement about an anonymous inner class is true?

A
It cannot implement interfaces.
B
The constructor cannot take arguments.
C
It can be declared from within a method.
D
It can directly implement multiple interfaces.

160Q
Given:
1. class MyClass {
2. public class YourClass {}
3. }
What can you use to create an instance of YourClass from a separate class?

A
MyClass mc = new YourClass();
B
YourClass yc = new YourClass();
C
MyClass mc = new MyClass(YourClass());
D
MyClass mc = new MyClass();
MyClass.YourClass yc = mc.new YourClass();

161Q
public class Both implements Runnable {
2. public char [] c = new char[2];
3. public Both() {
4. c[0] = 'A';
5. c[1] = 'B';
6. }
7.
8. public void run() {
9. int i = 1;
10. for(int j = 0; j < 2; j++) {
11. if (i == 1) {
12. System.out.println(c[1] + " " + c[0]);
13. i = 0;
14. }
15. else {
16. System.out.println(c[0] + " " + c[1]);
17. i = 1;
18. }
19. }
20. }
21. }
The Both class should print: B A A B Which main() method will allow this output by the
Both class?
A
public static void main(String [] args) {
new Thread(Both()).start();
}
B
public static void main(String [] args) {
new Thread(new Both()).start();
}
C
public static void main(String [] args) {
Thread bth = new Both();
bth.start();
}
D
Thread.start();public static void main(String [] args) {
Thread bth = new Both();
Thread.start();
}

162Q
These steps are used to define and execute a Thread.

1. Define a class that implements Runnable.


2.
3. Call the start() method of the Thread object.
Which process should be inserted on line 2 to complete these steps?

A
Override the run method.
B
Instantiate the Thread subclass.
C
Pass an instance of the Runnable object to the Thread constructor.
D
Pass an instance of the Thread object to the Runnable constructor and override the run
method.
163Q
Why is the run() method implemented when using a thread?

A
The run() method is used to instantiate the Thread.
B
The run() method is used to start the execution of the Thread.
C
The run() method is used as the constructor for the class implementing the Thread.
D
The run() method is used to define the code that should be executed when the Thread is
started.

164Q
Which method will start the execution of an instance myThread of a thread?

A
myThread.run()
B
myThread.join()
C
myThread.start()
D
myThread.isAlive()

165Q
public class Cookies implements Runnable {
2.
3. int pb = 3, z = 0;
4. for (;z < 15;z++) {
5. pb = pb + 3;
6. System.out.println(pb);
7. }
8. }
9.
10. public static void main(String [] args) {
11. Cookies ck = new Cookies();
12. new Thread(ck).start();
13. }
14. }
What should be inserted on line 2 to allow compilation to succeed?

A
public void set() {
B
public void run() {
C
public void start() {
D
public void execute() {

166Q
public class Jar extends Thread {
2. public void run() {
3. int gls = 4;
4. for (int t = 0; t < 3; t++) {
5. gls = (gls * 4)/2;
6. System.out.println(gls);
7. }
8. }
9.
10. public static void main(String [] args) {
11.
12.
13. }
14. }
To result in this output:

8
16
32
What should be inserted on lines 11 and 12?

A
Jar j = new Jar();
j.start();
B
Jar j = new Jar();
new Thread;
C
Thread t = new Thread();
t.start();
D
Thread t = new Thread(Jar);
t.start();

167Q
public class Sand implements Runnable {
2. public static void main(String [] args) {
3. Sand s = new Sand();
4. new Thread(s).start();
5. }
6.
7. public void run() {
8. double d = 1.2;
9. for (int x = 0; x < 2; x++) {
10. d = (d + 1.0);
11. System.out.println(d);
12. }
13. }
14. }
What is the result?

A
Compilation fails because of an error on line 3.
B
Compilation fails because of an error on line 4.
C
Compilation succeeds and the program prints:
2.2
3.2
D
Compilation succeeds and the program prints a blank line.
E
Compilation succeeds, but an exception occurs during program execution.
168Q
public class Beans implements Runnable {
2. public static void main(String [] args) {
3. Thread t = new Thread(new Beans);
4. t.start();
5. }
6.
7. public void run() {
8. for (int x = 0; x < 5; x++) {
9. System.out.println("This is iteration " + x);
10. }
11. }
12. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints a blank line.
C
Compilation succeeds, but an exception occurs during program execution.
D
Compilation succeeds and the program prints:
This is iteration 0
This is iteration 1

169Q
public class Bath implements Runnable {
2. public static void main(String [] args) {
3. Bath bth = new Bath();
4. new Thread(bth).start();
5. }
6.
7. public void run(bth) {
8. int h = 0, g = 0;
9. for (;g < 4;g++) {
10. h = h + 2;
11. System.out.println(h);
12. }
13. }
14. }
What is the result?

A
Compilation fails because of an error on line 4.
B
Compilation fails because of an error on line 7.
C
Compilation succeeds and the program prints:
2
4
6
8
D
Compilation succeeds and the program prints a blank line.

170Q
Which statement about a thread is true?

A
The notify() method cannot be used within a synchronized block.
B
A thread stops executing only when the stop() method is called.
C
The wait() method cannot be used within a synchronized block.
D
The wait() method is called on an object to stop execution of a thread until a notify() or
notifyAll() method is issued on the same object.

171Q
Which statement about scheduling thread execution is true?
A
The wait() method is called to place a thread at the back of the runnable pool to allow
threads of a lower priority to start.
B
The yield() method is called to place a thread at the back of the runnable pool to allow
threads of a lower priority to start.
C
The wait() method is called to place a thread at the back of the runnable pool to allow
threads of the same priority to start.
D
The yield() method is called to take a thread out of the running state and place it into the
runnable pool to allow threads of the same priority to start.

172Q
public class News implements Runnable {
2. public void run() {
3. for (int x = 0; x < 5; x++) {
4. System.out.println(x);
5. }
6. }
7.
8. public static void main(String [] args) {
9. News n = new News();
10. Thread t1 = new Thread(n);
11. Thread t2 = new Thread(n);
12. t1.start();
13. t2.start();
14. t1.start();
15. }
16. }
What is the result?

A
Compilation fails.
B
Compilation succeeds, but an exception occurs during program execution.
C
Compilation succeeds and the program prints two sets of numbers beginning with 0 and
ending with 5.
D
Compilation succeeds and the program prints three sets of numbers beginning with 0 and
ending with 5.

173Q
public class Red extends Thread {
2. public void run() {
3. for (int y = 0; y < 3; y++) {
4. System.out.println(y);
5. if (y == 1) { System.exit(0); }
6. }
7. }
8.
9. public static void main(String [] args) {
10. Red r = new Red();
11. Thread t1 = new Thread(r);
12. Thread t2 = new Thread(r);
13. t1.start();
14. t2.start();
15. }
16. }
Which result is possible?

A
Compilation fails.
B
Compilation succeeds and the program prints:
0
1
C
Compilation succeeds and the program prints:
0
1
2
0
1
2
D
Compilation succeeds, but an exception occurs during program execution.

174Q
public class Snow {
2. public static void main(String [] args) {
3. Snow s = new Snow();
4. new Thread() {
5. public void run() {
6. for (int w = 0; w < 2; w++) {
7. System.out.print(w);
8. }
9. }
10. }.start();
11. new Thread() {
12. public void run() {
13. for (int z = 5; z < 7; z++) {
14. System.out.print(z);
15. }
16. }
17. }.start();
18. }
19. }
public class Snow {
2. public static void main(String [] args) {
3. Snow s = new Snow();
4. new Thread() {
5. public void run() {
6. for (int w = 0; w < 2; w++) {
7. System.out.print(w);
8. }
9. }
10. }.start();
11. new Thread() {
12. public void run() {
13. for (int z = 5; z < 7; z++) {
14. System.out.print(z);
15. }
16. }
17. }.start();
18. }
19. }

public class Snow {


2. public static void main(String [] args) {
3. Snow s = new Snow();
4. new Thread() {
5. public void run() {
6. for (int w = 0; w < 2; w++) {
7. System.out.print(w);
8. }
9. }
10. }.start();
11. new Thread() {
12. public void run() {
13. for (int z = 5; z < 7; z++) {
14. System.out.print(z);
15. }
16. }
17. }.start();
18. }
19. }

What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints a blank line.
C
Compilation succeeds, but an exception occurs during program execution.
D
Compilation succeeds and the program prints the numbers 0, 1, 5, and 6, in some order.

175Q
Which statement about threads in deadlock is true?

A
It occurs when Thread1 and Thread2 are waiting for a lock held by Thread3.
B
It occurs when Thread1 is waiting for a lock held by Thread2, and Thread2 is waiting for
a lock held by Thread3.
C
It occurs when Thread1 is waiting for a lock held by Thread2, and Thread2 is waiting for
a lock held by Thread1.
D
It occurs when Thread1 is waiting for a lock held by Thread2, and Thread3 is waiting for
a lock held by Thread1.
176Q
public class MyThread implements Runnable {
2. private String holdA = "This is ";
3. private int[] holdB = {1,2,3,4,5,6,7,8,9,10};
4.
5. public static void main(String args[]) {
6. MyThread z = new MyThread();
7. (new Thread(z)).start();
8. (new Thread(z)).start();
9. }
10.
11. public synchronized void run() {
12. for(int w = 0;w < 10;w++) {
13. System.out.println(holdA + holdB[w] + ".");
14. }
15. }
16. }
What is the result?

A
Compilation fails because of an error on line 6.
B
Compilation fails because of an error on line 11.
C
Compilation fails because of errors on lines 7 and 8.
D
Compilation succeeds and the program prints each value in the holdB array at the end of
the "This is " line. Each value is printed two times before the program ends, and the
values are not printed in sequential order.
E
Compilation succeeds and the program prints each value in the holdB array at the end of
the "This is " line. Each value is printed in order from 1 to 10 and, after the value 10
prints, it starts printing the values 1 to 10 in order again.

177Q
Which statement about the join() method of the Thread class is true?
A
It is used to combine two threads so that they execute simultaneously.
B
It is used to allow other threads of the same priority a chance to execute.
C
It is used to cause the current thread to pause for a specified period of time.
D
It is used to cause the current thread to pause until the argument thread terminates.

178Q
public class Sleep implements Runnable {
2. public void run() {
3. for (int z = 0; z < 15; z++) {
4. System.out.println(z);
5. }
6. }
7.
8. public static void main(String [] args) {
9. Sleep s = new Sleep();
10. Thread ta = new Thread(s);
11. Thread tb = new Thread(s);
12. try {
13.
14.
15.
16.
17. }
18. catch (InterruptedException e) {
19. System.out.println(e);
20. }
21. }
22. }

The first set of numbers, 0 to 14, should print in its entirety. The second set of numbers, 0
to 14, should print in its entirety after the first set. Which body should be inserted in the
try block on line 13 to accomplish this?

A
ta.start();
ta.join();
tb.start();
B
ta.start();
tb.join();
tb.start();
C
ta.start();
ta.wait();
tb.join();
tb.start();
D
ta.start();
tb.wait();
tb.start();
tb.join();

179Q
public class Geo {
2. public static void main(String [] args) {
3. Geo g = new Geo();
4. final Object o1 = new Object();
5. final Object o2 = new Object();
6. Thread tx = new Thread(new Runnable() {
7. public void run() {
8. synchronized(o1) {
9. synchronized(o2) {
10. calc();
11. }
12. }
13. }
14. });
15.
16. Thread ty = new Thread(new Runnable() {
17. public void run() {
18. synchronized(o2) {
19. synchronized(o1) {
20. calc();
21. }
22. }
23. }
24. });
25. tx.start();
26. ty.start();
27. }
30. }
Which statement about the Geo.java program is true?

A
An exception can occur because of the two threads.
B
The program contains invalid synchronize statements.
C
A deadlock situation can occur with the two threads.
D
The program is constructed in a way that will avoid deadlock.

180Q
class Gotit2 {
2. int a, b;
3. public void geta(int g) {
4. a = a + g;
5. }
6. public void getb(int g) {
7. b = b + g;
8. }
9. public synchronized void getboth(int g) {
10. geta(g);
11. getb(g);
12. }
13. public synchronized boolean testit() {
14. return (a != b);
15. }
16. }

Which statement is true?

A
The testit() method will always return true.
B
The testit() method will always return false.
C
The testit() method can return true if geta() and getb() are called by multiple threads.
D
The testit() method can return true if the getboth() method is called by multiple threads.

181Q
public class Meet implements Runnable {
2. public void run() {
3. for (int y = 0; y < 20; y++) {
4. System.out.println(y);
5. }
6. }
7.
8. public static void main(String [] args) {
9. Meet m = new Meet();
10. Thread t1 = new Thread(m);
11. Thread t2 = new Thread(m);
12. try {
13. t1.start();
14. join(t1);
15. t2.start();
16. }
17. catch (Exception e) {
18. System.out.println(e);
19. }
20. }
21. }
What is the result?

A
Compilation fails.
B
Compilation succeeds, but an exception occurs during program execution.
C
Compilation succeeds and the program prints two sets of numbers from 0 to 19 in
random order.
D
Compilation succeeds and the program prints one set of numbers from 0 to 19, and then
repeats the set of numbers from 0 to 19.

182Q
What is used when defining threads to prevent more than one thread from executing
critical parts of the same object concurrently?
A
join
B
wait
C
notify
D
synchronized

183Q
Which statement about the notify() method of an object is true?

A
It is used to place every thread into a wait mode.
B
It is used to wake up every thread that is waiting.
C
It is used to place a single thread into a wait mode.
D
It is used to wake up a single thread that is waiting.

184Q
Which statement about the wait() method of an object is true?

A
The parent class for the wait() method is java.lang.Thread.
B
The wait() method must be called from within a synchronized block.
C
The wait() method is only used in conjunction with the join() method.
D
The thread calling the wait() method does not release the object's lock flag.
185Q
public class Tack extends Thread {
2. public static void main(String [] args) {
3. Tack tk = new Tack();
4. new Thread(tk).start();
5. }
6.
7. public void run() {
8. int x = 0, z = 5;
9. for (;x<4;x++) {
10. z = z + 10;
11. System.out.print(z + " ");
12. }
13. }
14. }
What is the result?

A
Compilation fails because of an error on line 1.
B
Compilation fails because of an error on line 4.
C
Compilation succeeds and the program prints: 15 25 35 45
D
Compilation succeeds, but an exception occurs during program execution.
204Q

public class GetIt {


2. public static void main(String args[]) {
3. double x[] = {10.2, 9.1, 8.7};
4. int i[] = new int[3];
5. for(int a = 0;a < (x.length);a++) {
6.
7. System.out.println(i[a]);
8. }
9. }
10. }
The GetIt class should print the following:

11
10
9
Which line should you insert on line 6 to accomplish this?

A
i[a] = ((int)Math.min(x[a]));
B
i[a] = ((int)Math.max(x[a]));
C
i[a] = ((int)Math.ceil(x[a]));
D
i[a] = ((int)Math.floor(x[a]));

205Q
Given:

1. public class testit {


2. public static void main(String [] args) {
3. double x = 30.456;
4. System.out.println(Math.floor(x));
5. }
6. }
What is the output?

206Q
Given:

1. public class Plant {


2. public static void main(String [] args) {
3. float j = 1.34f;
4. float k = 0.64f;
5. int z = (int)Math.round(j * k);
6. System.out.println(z);
7. }
8. }
Given that the value of 1.34 * 0.64 is 0.8576, what is the output?

207Q
Given:

1. public class Gush {


2. public static void main(String [] args) {
3. // Insert method body here
4. }
5. }
Which main method body should be inserted at line 3 to result in the printing of the
tangent of 76 degrees?

A
double p = Math.tan(Math.toDegrees(76)); System.out.println(p);
B
double p = Math.tangent(Math.toRadians(76)); System.out.println(p);
C
double p = Math.toRadians(76); double f = Math.tan(p); System.out.println(f);
D
double p = Math.toDegrees(76); double f = Math.tangent(p); System.out.println(f);

208Q
Given:

1. public class Shade {


2. public static void main(String [] args) {
3. float x, y;
4. x = 2.1f;
5. y = 1.3f;
6.
7. }
8. }
Which statement, inserted on line 6, would produce the output "2.1"?

A
System.out.println(Math.min(x, y));
B
System.out.println(Math.max(x, y));
C
System.out.println(Math.ceil(x, y));
D
System.out.pirntln(Math.floor(x, y));
209Q
Given:

1. public class GorLeg {


2. public static void main(String [] args) {
3. String gl = new String("Hello");
4. String lg = gl;
5. lg.concat(" you ");
6. lg += " there!";
7. System.out.println(lg);
8. }
9. }
What is the result?

A
Compilation fails.
B
Compilation succeeds and the program prints: Hello
C
Compilation succeeds and the program prints: Hello there!
D
Compilation succeeds and the program prints: Hello you there!

210Q
Given:

1. public class Shoe {


2. public static void main(String [] args) {
3. String tie = "white";
4. String knot = tie;
5. tie.concat("laces");
6. System.out.println(tie);
7. }
8. }
What is the result?
A
Compilation fails because of an error on line 4.
B
Compilation fails because of an error on line 5.
C
Compilation succeeds and the program prints "white".
D
Compilation succeeds and the program prints "whitelaces".

211Q
Given:

1. public class Lth {


2. public static void main(String [] args) {
3. String c = "foodshop";
4. String g = c;
5. g = c.substring(3);
6. c = g;
7. System.out.println(c);
8. }
9. }
What is the output?

212Q
Given:

1. public class Morg {


2. public static void main(String [] args) {
3. String lift = "heavy";
4. String tow = "tough";
5. lift.concat(tow);
6. System.out.println(lift);
7. }
8. }
What is the output?

213Q
Which statement about the Map interface is true?

A
Entries are placed in a Map using the values() method.
B
Entries are placed in a Map using the entrySet() method.
C
A key/value association is added to a Map using the put() method.
D
A key/value association is added to a Map using the putAll() method.

214Q
Which statement about the java.util.Set interface is true?

A
It allows duplicates.
B
It is an ordered collection.
C
It does not allow duplicates.
D
It is a collection of key and value pairs.

215Q
Which class contains ordered elements in a collection?

A
java.util.Set
B
java.util.ArrayList
C
java.util.Map
D
java.util.Observable

216Q
What are two interfaces implemented by the java.util.Hashtable class? (Choose two.)
A
java.util.Map
B
java.util.Set
C
java.util.List
D
java.lang.Cloneable
E
java.util.Collection
F
java.lang.Comparable

217Q
Which statement about the java.util.HashSet class is true?

A
The implementation is synchronized.
B
It does not permit the null element.
C
It does not guarantee the iteration order of the set.
D
It guarantees that the set is and will remain in a particular order.

218Q
Which statement about the java.util.SortedSet class is true?

A
A set can contain duplicate elements.
B
A set can contain any number of null elements.
C
It does not guarantee the set will be processed in a particular order.
D
All elements inserted into a sorted set must implement the Comparable interface.

219Q
Which interface is implemented to generate a series of elements, one at a time?

A
Map
B
SortedSet
C
Comparator
D
Enumeration

220Q
Which class will allow you to parse and print numbers in the format of the user's region?

A
BitSet
B
Locale
C
Hashtable
D
Observable
E
SimpleTimeZone

221Q
Which statement about the java.util.Vector class is true?
A
It represents a growable array of objects.
B
It represents a last-in-first-out stack of objects.
C
It represents a hashtable-based map with weak keys.
D
It represents a task that can be scheduled for one-time or repeated execution.

Você também pode gostar