Question: What is true of the following code? (Choose two.) A. As written, the code prints one line. B. As written, the code prints two lines.

What is true of the following code? (Choose two.) 

3: public static void main(String[] args) { 4: var prefix= "r"; 5:

A. As written, the code prints one line.

B. As written, the code prints two lines.

C. As written the code does not compile.

D. If line 7 is uncommented, the code prints one line.

E. If line 7 is uncommented, the code prints two lines.

F. If line 7 is uncommented, the code does not compile.

3: public static void main(String[] args) { 4: var prefix= "r"; 5: var pets = List.of("rabbit", "snake", "turtle"); 6: 7: 8: 9: 10: } // prefix = "t"; pets.forEach (p -> { if (p.startsWith(prefix)) System.out.println(p); } );

Step by Step Solution

3.44 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

The code in the image is written in Java and uses the lambda expression inside forEach to iterate ov... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Oracle Questions!