Submitted by c-admin on Tue, 05/28/2019 - 03:41
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.
Submitted by c-admin on Tue, 05/28/2019 - 03:36
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.
Submitted by c-admin on Tue, 05/28/2019 - 03:31
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.
Submitted by c-admin on Tue, 05/28/2019 - 03:26
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; }
Submitted by c-admin on Tue, 05/28/2019 - 03:22
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