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){}
    
  
  
 
  
        
    
      
      Submitted by c-admin on Tue, 05/28/2019 - 03:18    
  
  
    Given:
class OverloadingTest{
void m1(int x){
System.out.println("m1 int");
}
void m1(double x){
System.out.println("m1 double");
}
void m1(String x){
System.out.println("m1 String");
}
}
public class TestClass {
public static void main(String[] args) throws Exception {
OverloadingTest ot = new OverloadingTest();
ot.m1(1.0);
}
}
What will be the output?
Select 1 option
A. It will fail to compile.
B. m1 int
C. m1 double
D. m1 String
    
  
  
 
  
        
    
      
      Submitted by c-admin on Tue, 05/28/2019 - 03:11    
  
  
    Consider the following class...
class TestClass{
void probe(int... x) { System.out.println("In ..."); } //1
void probe(Integer x) { System.out.println("In Integer"); } //2
void probe(long x) { System.out.println("In long"); } //3
void probe(Long x) { System.out.println("In LONG"); } //4
public static void main(String[] args){
Integer a = 4; new TestClass().probe(a); //5
int b = 4; new TestClass().probe(b); //6
}
}
What will it print when compiled and run?
Select 2 options
A. In Integer and In long
B. In ... and In LONG, if //2 and //3 are commented out.
C. In Integer and In ..., if //4 is commented out.
D. It will not compile, if //1, //2, and //3 are commented out.
E. In LONG and In long, if //1 and //2 are commented out.
    
  
  
 
  
        
    
      
      Submitted by c-admin on Tue, 05/28/2019 - 03:06    
  
  
    Which of the following are true regarding overloading of a method?
Select 1 option
A. An overloading method must have a different parameter list and same return type as that of the overloaded method.
B. If there is another method with the same name but with a different number of arguments in a class then that method can be called as overloaded.
C. If there is another method with the same name and same number and type of arguments but with a different return type in a class then that method can be called as overloaded. 
D. An overloaded method means a method with the same name and same number and type of arguments exists in the super class and sub class.
    
  
  
 
Pages