Chapter 2Controlling Program Flow
- Which statements are true of the following code? (Choose two.)
public class Penguins {
public static void main(String[] args) {
var pen = new Penguins();
pen.length("penguins");
pen.length(5);
pen.length(new Object());
}
public void length(Object obj) {
if (obj instanceof String x)
System.out.println(x.length());
} }
- The code compiles as is.
- One line causes compiler errors.
- Two lines cause compiler errors.
- If any lines that do not compile are removed, ...
Get OCP Oracle Certified Professional Java SE 17 Developer Practice Tests now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.