Set 10

Multiple Choice Question

QID: 
125

Consider the following class.

class TestClass{
void probe(Object x) { System.out.println("In Object"); } //3 
void probe(Number x) { System.out.println("In Number"); } //2 
void probe(Integer x) { System.out.println("In Integer"); } //2 
void probe(Long x) { System.out.println("In Long"); } //4
public static void main(String[] args){ double a = 10;
new TestClass().probe(a);
}
}

What will be printed?

Select 1 option

A. In Number
B. In Object
C. In Long
D. In Integer
E. It will not compile.

Multiple Choice Question

QID: 
124

Consider the following code:

public class TestClass{
   public void method(Object o){
      System.out.println("Object Version");
   }
   public void method(java.io.FileNotFoundException s){
      System.out.println("java.io.FileNotFoundException Version");
   }
   public void method(java.io.IOException s){
      System.out.println("IOException Version");
   }
   public static void main(String args[]){
      TestClass tc = new TestClass();
      tc.method(null);
   }
}

What would be the output when the above program is compiled and run? (Assume that FileNotFoundException is a subclass of IOException, which in turn is a subclass of Exception)

Select 1 option

A. It will print Object Version
B. It will print java.io.IOException Version
C. It will print java.io.FileNotFoundException Version
D. It will not compile.
E. It will throw an exception at runtime.

Multiple Choice Question

QID: 
123

What will be printed when the following code is compiled and run?

public class LoadTest{
    public static void main(String[] args) throws Exception {
         LoadTest t = new LoadTest();
         int i = t.getLoad();
         double d = t.getLoad();
         System.out.println( i + d );
    }
    public int getLoad() {
        return 1;
    }
    public double getLoad(){ 
        return 3.0;
    }
}

Select 1 option

A. 13.0
B. 4.0
C. 4 
D. The code will not compile.

Multiple Choice Question

QID: 
122

Given the following code, which method declarations can be inserted at line 1 without any problems?

public class OverloadTest{
public int sum(int i1, int i2) { return i1 + i2; }
// 1
}

Select 3 options

A. public int sum(int a, int b) { return a + b; }
B. public int sum(long i1, long i2) { return (int) i1; }
C. public int sum(int i1, long i2) { return (int) i2; }
D. public long sum(long i1, int i2) { return i1 + i2; }
E. public long sum(int i1, int i2) { return i1 + i2; }

Multiple Choice Question

QID: 
121

Consider the following code:

public class Varargs{
public void test(){
test1(10); //1
test1(10, 20); //2
}
public static void main(String[] args){
new Varargs().test();
}
//insert method here.
}

Which of the following lines can be added independently to the above class so that it will run without any errors or exceptions?

Select 2 options

A. public void test1(int i, int j){}
B. public void test1(int i, int... j){}
C. public void test1(int... i){}
D. public void test1(int i...){}
E. public void test1(int[] i){}

Pages

Search the Web

Custom Search

Searches whole web. Use the search in the right sidebar to search only within javajee.com!!!

Quick Notes Finder Tags

Activities (1) advanced java (1) agile (3) App Servers (6) archived notes (2) ArrayLists (1) Arrays (2) 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) (52) 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 (4) http monitoring (2) Inheritance (4) intellij (1) java 8 notes (4) Java 9 (1) Java Concepts (7) Java Core (7) 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 (8) Javascript Frameworks (1) Java SE Professional (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) resources (1) 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)