Which of the following statements are correct?
```
I:
File file = new File("input.txt");
try (Scanner input = new Scanner(file)) {
String line = input.nextLine();
}
II:
try (File file = new File("input.txt");
Scanner input = new Scanner(file);) {
String line = input.nextLine();
}
III:
File file;
try (file = new File("input.txt");
Scanner input = new Scanner(file);) {
String line = input.nextLine();
}
IV:
File file;
Scanner input;
try (file = new File("input.txt");
input = new Scanner(file);) {
String line = input.nextLine();
}```
a. I
b. II
c. III
d. IV
a File is not a subtyp of AutoCloseable. So it cannot be used to open a resource in a try-with-resources.
You might also like to view...
________ is a microblogging platform for social networking
Fill in the blank(s) with correct word
Consider the Java code segment below:
``` Polygon poly2 = new Polygon(); poly2.addPoint(100, 30); poly2.addPoint(100, 130); ``` Which of the following will create a polygon that is a square? a. poly2.addPoint(100, 60); poly2.addPoint(100, 130); b. poly2.addPoint(200, 130); poly2.addPoint(200, 30); c. poly2.addPoint(200, 60); poly2.addPoint(200, 130); d. poly2.addPoint(100, 130); poly2.addPoint(100, 230);