请阅读下面的程序public class Demo { public static int sum(int a, int b) { return a + b; } public static float sum(int a, ____ b) { _____ a + b; }}
举一反三
- 请阅读下面的程序,在空白处填写正确的代码,令代码实现方法的重载。public class Demo {public static int sum(int a, int b) {return a + b;}public static float sum(int a, ____ b) {return a + b;}}
- 请阅读下面的程序 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); } } 下列选项中,哪一个是程序的运行结果()
- (7-12)请阅读程序,写出程序运行结果。 class A{ static String name="tom"; static int getX() { return 2; } int getY() { return 3; } } class B extends A{ static String name="Tuny"; static int getX() { return 4; } int getY() { return 5; } } class C extends A{ static String name="Tuny"; static int getX() { return 4; } int getY() { return 5; } } interface D{ int getY(); } class E implements D{ public int getY() { return 6; } } public class Demo{ public static void main(String[] args) { A a=new A(); A b=new B(); A c=new C(); D d=new E(); int sum=a.name.length()+b.getX()+c.getY()+d.getY(); System.out.println(sum); } }
- 写出程序的运行结果。 public class Demo{ public static void main(String args[]) { int b = get(); System.out.println(b); } public static int get() { try { return 1; } finally { return 2; } } }
- 中国大学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); }}???处填入( )时,编译程序会出错。