中国大学MOOC: public class Test{ public static void main(String[ ] args) { int result =???; System.out.println(result); } public static int operate(double a, int b) { return 10*(int)(a+b); } public static int operate(int a, double b) { return 100*(int)(a+b); } public static int operate(double a, double b) { return 1000*(int)(a+b); }}???处填入( )时,编译程序会出错。
举一反三
- public class test1 { public static int add(int a, int b) { return a+b; } public static double add(double a, double b) { return a+b; } ________________ ___________________ { ________________ ___________________ } public static void main(String[] args) { System.out.println("调用add方法:"+add(2.1,3.4,4.5)); } }
- 以下代码运行后输出的内容( )public class Main { public static double div(int a, int b) { return (double)a/b; } public static int div(int a, int b) { return a/b; } public static void main(String[] args) { System.out.println(div(5, 2)); } } A: 2.5 B: 2 C: 输出内容不确定 D: 程序错误,无法运行
- 请阅读下面的程序 public class Demo { public static void sum(int a, int b) { System.out.println("int:" + (a + b)); } public static void sum(int a, float b) { System.out.println("float:" + (a + b)); } public static void sum(int a, double b) { System.out.println("double:" + (a + b)); } public static void main(String[] args) { int a = 10; long b = 20; sum(a, b); } } 下列选项中,哪一个是程序的运行结果()
- 关于下列代码说法正确的是( ) public class Foo{ public int add(int a,int b){ return a+b; } public static void main(String[] args){ Foo foo = null; System.out.println(foo.add(10,20)); } }
- 请说出E类中【代码1】,【代码2】的输出结果。 interface A { double f(double x,double y); } class B implements A { public double f(double x,double y) { return x*y; } int g(int a,int b) { return a+b; } } public class E { public static void main(String args[]) { A a = new B(); System.out.println(a.f(3,5)); //【代码1】 B b = (B)a; System.out.println(b.g(3,5)); //【代码2】 } }