public class Test{
   returnType methodA(byte x,double y){
    return(short)x/y*2;
}
}
returnType请问返回类型是什么才不报错?
为什么short不能
?不是强制转换了吗?

解决方案 »

  1.   

    小问题太多了不好意思开个新贴:
    public class Test5{
    public static void main(String args[]){
    Object o=new String("abcd");
    String s=(String)o;
    System.out.println(s);
    System.oot.println(o);
    }
    }System.oot.println(o);为什么有错?不会自动调用tostring()方法吗?
      

  2.   

    System.oot.println(o);
    你这是输入错误:System.out.println(o);
    仔细一点
      

  3.   

    public class Test{
       returnType methodA(byte x,double y){
        return(short)x/y*2;
    }
    }
    你这个表达式(short)x/y*2;是表示把x强制转换成short型,但由于y是double型,所以整个式子中都将转换成double型来运算,结果也是一个double,所以你的返回类型应该为double
      

  4.   

    cannot convert from double to short;
    return (short)x/y*2; = return ((short)x)/y*2;返回double;
    return (short)(x/y*2);返回short