Java Programmer I

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 ().

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: 
551

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)

True or False

QID: 
550

The following program will print java.lang.ArithmeticException: / by zero

class Test{
public static void main(String[] args){
int d = 0;
try{
int i = 1 / (d* doIt());
} catch (Exception e){
System.out.println(e);
}
}
public static int doIt() throws Exception{
throw new Exception("Forget It");
}
}

Select 1 option

A. True
B. False

Multiple Choice Question

QID: 
549

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.

Pages

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) Arrays (1) Best Practices (12) Best Practices (Design) (3) Best Practices (Java) (7) Best Practices (Java EE) (1) BigData (3) Chars & Encodings (6) coding problems (2) Collections (15) contests (3) Core Java (All) (55) course plan (2) Database (12) Design patterns (8) dev tools (3) downloads (2) eclipse (9) Essentials (1) examples (14) Exception (1) Exceptions (4) Exercise (1) exercises (6) Getting Started (18) Groovy (2) hadoop (4) hibernate (77) hibernate interview questions (6) History (1) Hot book (5) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (9) java ee exercises (1) java ee interview questions (2) Java Elements (16) Java Environment (1) Java Features (4) java interview points (4) java interview questions (4) javajee initiatives (1) javajee thoughts (3) Java Performance (6) Java Programmer 1 (11) Java Programmer 2 (7) Javascript Frameworks (1) Java SE Professional (1) JPA 1 - Module (6) JPA 1 - Modules (1) JSP (1) Legacy Java (1) linked list (3) maven (1) Multithreading (16) NFR (1) No SQL (1) Object Oriented (9) OCPJP (4) OCPWCD (1) OOAD (3) Operators (4) Overloading (2) Overriding (2) Overviews (1) policies (1) programming (1) Quartz Scheduler (1) Quizzes (17) RabbitMQ (1) references (2) restful web service (3) Searching (1) security (10) Servlets (8) Servlets and JSP (31) Site Usage Guidelines (1) Sorting (1) source code management (1) spring (4) spring boot (3) Spring Examples (1) Spring Features (1) spring jpa (1) Stack (1) Streams & IO (3) Strings (11) SW Developer Tools (2) testing (1) troubleshooting (1) user interface (1) vxml (8) web services (1) Web Technologies (1) Web Technology Books (1) youtube (1)