Which code fragment inserted at line ***, enables the code to compile?

Given the code fragment:

Which code fragment inserted at line ***, enables the code to compile?

Given the code fragment:

Which code fragment inserted at line ***, enables the code to compile?

A.
public void process () throws FileNotFoundException, IOException { super.process ();
while ((record = br.readLine()) !=null) {
System.out.println(record);
}}

B.
public void process () throws IOException {
super.process ();
while ((record = br.readLine()) != null) {
System.out.println(record);
}}

C.
public void process () throws Exception {
super.process ();
while ((record = br.readLine()) !=null) {
System.out.println(record);
}}

D.
public void process (){
try {
super.process ();
while ((record = br.readLine()) !=null) {
System.out.println(record);
}
} catch (IOException | FileNotFoundException e) { }
}

E.
public void process (){
try {
super.process ();
while ((record = br.readLine()) !=null) {
System.out.println(record);
}
} catch (IOException e) {}
}

Explanation:

A: Compilation fails: Exception IOException is not compatible with throws clause in Base.process()
B: Compilation fails: Exception IOException is not compatible with throws clause in Base.process()
C: Compilation fails: Exception Exception is not compatible with throws clause in Base.process()
D: Compilation fails: Exception FileNotFoundException has already been caught by the alternative
IOException
Alternatives in a multi-catch statement cannot be related to subclassing Alternative
java.io.FileNotFoundException is a subclass of alternative java.io.IOException
E: compiles …



Leave a Reply 1

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