Given:
1 . abstract class Shape {
2 . Shape ( ) { System.out.println ("Shape"); }
3 . protected void area ( ) { System.out.println ("Shape"); }
4 . }
5 .
6 . class Square extends Shape {
7 . int side;
8 . Square int side {
9 . /* insert code here */
1 0. this.side = side;
1 1. }
1 2. public void area ( ) { System.out.println ("Square"); }
1 3. }
1 4. class Rectangle extends Square {
1 5. int len, br;
1 6. Rectangle (int x, int y) {
1 7. /* insert code here */
1 8. len = x, br = y;
1 9. }
2 0. void area ( ) { System.out.println ("Rectangle"); }
2 1. }
Which two modifications enable the code to compile?
Given:
class ImageScanner implements AutoCloseable {
public void close () throws Exception {
System.out.print ("Scanner closed.");
}
public void scanImage () throws Exception {
System.out.print ("Scan.");
throw new Exception("Unable to scan.");
}
}
class ImagePrinter implements AutoCloseable {
public void close () throws Exception {
System.out.print ("Printer closed.");
}
public void printImage () {System.out.print("Print."); }
}
and this code fragment:
try (ImageScanner ir = new ImageScanner();
ImagePrinter iw = new ImagePrinter()) {
ir.scanImage();
iw.printImage();
} catch (Exception e) {
System.out.print(e.getMessage());
}
What is the result?
Given the code fragment:
List<Integer> nums = Arrays.asList (10, 20, 8):
System.out.println (
//line n1
);
Which code fragment must be inserted at line n1 to enable the code to print the maximum number in the nums
list?
Given the code fragments:
and
Which two modifications enable to sort the elements of the emps list? (Choose two.)