JAVA Programming :: Basic Concepts - Discussion
Home > JAVA Programming > Basic Concepts > MCQs Questions Discussion
44 / 64
What is the output for the below code?
public class Test {
public static void printValue(int i, int j, int k){
System.out.println("int");
}
public static void printValue(byte...b){
System.out.println("long");
}
public static void main(String... args) {
byte b = 9;
printValue(b,b,b);
}
}
public class Test {
public static void printValue(int i, int j, int k){
System.out.println("int");
}
public static void printValue(byte...b){
System.out.println("long");
}
public static void main(String... args) {
byte b = 9;
printValue(b,b,b);
}
}
Along
Bint
CCompilation fails
DCompilation clean but throws RuntimeException
Answer: Option (Login/Signup)
Show Explanation
Asked In ::
STEP-BY-STEP
The first printValue() method is a concept of widening, whereas the second printValue() method is a an example of var-arg method. As widening dominates over var-arg method, hence the first printValue() method gets executed. byte being a small primitive type gets upcasted into a bigger primitive type int through widening.
Hence, int is the output.
Read Full Answer
Report Error
Please Login First Click Here