Overloading Methods and Constructors

Quiz Guidelines

 

Multiple Choice Question

QID: 
117

Consider the following class...

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

What will be printed?

Select 1 option
A. In Integer
B. In Object
C. In Long
D. It will not compile

Multiple Choice Question

QID: 
116

Consider the following method...

public int setVar(int a, int b, float c) { ...}

Which of the following methods correctly overload the above method?

Select 2 options

A. public int setVar(int a, float b, int c){
         return (int)(a + b + c); }
B. public int setVar(int a, float b, int c){
         return this(a, c, b); }
C. public int setVar(int x, int y, float z){
         return x+y); }
D. public float setVar(int a, int b, float c){
        return c*a; }
E. public float setVar(int a){
      return a; }

Pages