Which regular expression, inserted at line 12, correctly splits test into "Test A", "Test B", and "Test C"?

Given:

11. String test = “Test A. Test B. Test C.”;
12. // insert code here
13. String[] result = test.split(regex);

Which regular expression, inserted at line 12, correctly splits test into “Test A”, “Test B”, and “Test C”?

Given:

11. String test = “Test A. Test B. Test C.”;
12. // insert code here
13. String[] result = test.split(regex);

Which regular expression, inserted at line 12, correctly splits test into “Test A”, “Test B”, and “Test C”?

A.
String regex = “”;
Test
Test
Compilation fails because of an error in line 3.

B.
String regex = ” “;
Test
Test
Compilation fails because of an error in line 7.

C.
String regex = “.*”;
C:
<no output>
D:
Test
E:
Test A
Test B
Test C
F:
Main.java:12: illegal escape character
String regex = “\\w[ \.] +”;
^
1 error
QUESTION 2
Given:
1. interface A { public void aMethod(); }
2. interface B { public void bMethod(); }
3. interface C extends A,B { public void cMethod(); }
4. class D implements B {
5. public void bMethod(){}
6. }
7. class E extends D implements C {
8. public void aMethod(){}
9. public void bMethod(){}
10. public void cMethod(){}
11. }
What is the result?
Compilation fails because of an error in line 9.

D.
String regex = “\\s”;
If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.

E.
String regex = “\\.\\s*”;
If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.

F.
String regex = “\\w[ \.] +”;
If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

A.
String regex = “”;
Test
Test
Compilation fails because of an error in line 3.

B.
String regex = ” “;
Test
Test
Compilation fails because of an error in line 7.

C.
String regex = “.*”;
C:
<no output>
D:
Test
E:
Test A
Test B
Test C
F:
Main.java:12: illegal escape character
String regex = “\\\\w[ \\.] +”;
^
1 error
QUESTION 2
Given:
1. interface A { public void aMethod(); }
2. interface B { public void bMethod(); }
3. interface C extends A,B { public void cMethod(); }
4. class D implements B {
5. public void bMethod(){}
6. }
7. class E extends D implements C {
8. public void aMethod(){}
9. public void bMethod(){}
10. public void cMethod(){}
11. }
What is the result?
Compilation fails because of an error in line 9.

A.
String regex = “”;
Test
Test
Compilation fails because of an error in line 3.

B.
String regex = ” “;
Test
Test
Compilation fails because of an error in line 7.

C.
String regex = “.*”;
C:
<no output>
D:
Test
E:
Test A
Test B
Test C
F:
Main.java:12: illegal escape character
String regex = “\\\\\\\\w[ \\\\.] +”;
^
1 error
QUESTION 2
Given:
1. interface A { public void aMethod(); }
2. interface B { public void bMethod(); }
3. interface C extends A,B { public void cMethod(); }
4. class D implements B {
5. public void bMethod(){}
6. }
7. class E extends D implements C {
8. public void aMethod(){}
9. public void bMethod(){}
10. public void cMethod(){}
11. }
What is the result?
Compilation fails because of an error in line 9.

A.
String regex = “”;
Test
Test
Compilation fails because of an error in line 3.

B.
String regex = ” “;
Test
Test
Compilation fails because of an error in line 7.

C.
String regex = “.*”;
C:
<no output>
D:
Test
E:
Test A
Test B
Test C
F:
Main.java:12: illegal escape character
String regex = “\\\\\\\\\\\\\\\\w[ \\\\\\\\.] +”;
^
1 error
QUESTION 2
Given:
1. interface A { public void aMethod(); }
2. interface B { public void bMethod(); }
3. interface C extends A,B { public void cMethod(); }
4. class D implements B {
5. public void bMethod(){}
6. }
7. class E extends D implements C {
8. public void aMethod(){}
9. public void bMethod(){}
10. public void cMethod(){}
11. }
What is the result?
Compilation fails because of an error in line 9.

D.
String regex = “\\\\s”;
If you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.

E.
String regex = “\\\\.\\\\s*”;
If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.

F.
String regex = “\\\\w[ \\.] +”;
If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

Explanation:
A:
T
e
s
t

A

T
e
s
t

B

T
e
s
t

C

B:
Test



Leave a Reply 1

Your email address will not be published. Required fields are marked *


fjbo221

fjbo221

The selections should be

A. String regex = “”;
B. String regex = ” “;
C. String regex = “.*”;
D. String regex = “\\s”;
E. String regex = “\\.\\s*”;
F. String regex = “\\w[ \.] +”;

And “E” is correct.