About Question enthuware.ocajp.i.v7.2.991 :
Posted: Sat Jun 15, 2013 2:46 pm
For this question -
What can be the return type of method getSwitch so that this program compiles and runs without any problems?
"The return type cannot be byte, short, or char because the expression x - 20/x + x*x; returns an int."
How do we know that it returns an int? (Thanks in advance for your help!)
What can be the return type of method getSwitch so that this program compiles and runs without any problems?
Code: Select all
public class TestClass{
public static XXX getSwitch(int x){
return x - 20/x + x*x;
}
public static void main(String args[]){
switch( getSwitch(10) ){
case 1 :
case 2 :
case 3 :
default : break;
}
}
}
How do we know that it returns an int? (Thanks in advance for your help!)