JavaQuizzes

Quiz Guidelines

 

Multiple Choice Question

QID: 
552

Consider the following class:

public class PortConnector{
public PortConnector(int port) throws IOException{
...lot of valid code.
}
...other valid code.
}

You want to write another class CleanConnector that extends from PortConnector. Which of the following statements should hold true for CleanConnector class?

Select 1 option

A. It is not possible to define CleanConnector that does not throw IOException at instantiation.
B. PortConnector class itself is not valid because you cannot throw any exception from a constructor.
C. CleanConnector's constructor cannot throw any exception other than IOException.
D. CleanConnector's constructor cannot throw any exception other than subclass of IOException.
E. CleanConnector's constructor cannot throw any exception other than superclass of IOException.
F. None of these.

Multiple Choice Question

QID: 
553

How can you fix the following code to make it compile?

import java.io.*;
class Great {
    Public void doStuff() throws FileNotFoundException{
    }    
}
class Amazing extends Great { 
  public void doStuff() throws IOException, IllegalArgumentException
  }    
}
public class TestClass {
    public static void main(String[] args) throws IOException{
        Great g = new Amazing();
        g.doStuff();
    }
}

Assume that changes suggested in a option are to be applied independent of other options.

Select 2 options

A. Change do Stuff in Amazing to throw only Illegal Argument Exception.
B. Change do Stuff in Great to throw only File Not Found Exception as well as Illegal Argument Exception.
C. Change do Stuff in Amazing to throw only IO Exception.
D. Change do Stuff in Great to throw only IO Exception instead of File Not Found Exception.
E. Replace g.doStuff() to ((Amazing) g).do Stuff ().

Pages