Submitted by c-admin on Wed, 06/05/2019 - 06:51
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 ().
Submitted by c-admin on Wed, 06/05/2019 - 06:48
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.
Submitted by c-admin on Wed, 06/05/2019 - 06:45
Consider that you are writing a set of classes related to a new Data Transmission Protocol and have created your own exception hierarchy derived from java.lang.Exception as follows:
enthu.trans.ChannelException
+-- enthu.trans.DataFloodingException,
enthu.trans.FrameCollisionException
You have a TransSocket class that has the following method:
long connect(String ipAddr) throws ChannelException
Now, you also want to write another "AdvancedTransSocket" class, derived from "TransSocket" which overrides the above mentioned method. Which of the following are valid declaration of the overriding method?
Select 2 options
A. int connect(String ipAddr) throws DataFloodingException
B. int connect(String ipAddr) throws ChannelException
C. long connect(String ipAddr) throws FrameCollisionException
D. long connect(String ipAddr) throws Exception
E. long connect(String str)
Submitted by c-admin on Wed, 06/05/2019 - 06:36
Given the following program, which statement is true?
class SomeClass{
public static void main( String args[ ] ){
if (args.length == 0 ){
System.out.println("no arguments") ;
}
else{
System.out.println( args.length + " arguments") ;
}
}
}
Select 1 option
A. The program will fail to compile.
B. The program will throw a NullPointerException when run with zero arguments.
C. The program will print no arguments and 1 arguments when called with zero and one arguments.
D. The program will print no arguments and 2 arguments when called with zero and one arguments.
E. The program will print no arguments and 3 arguments when called with zero and one arguments.
Submitted by c-admin on Wed, 06/05/2019 - 06:33
Which of the following standard Java exception classes extend java.lang.RuntimeException?
Select 4 options
A. java.lang.SecurityException
B. java.lang.ClassCastException
C. java.lang.NullPointerException
D. java.lang.CloneNotSupportedException
E. java.lang.IndexOutOfBoundsException
Pages