以下静态方法的定义中正确的是()
A: static void show(String name){ System.out.println(name);
}
B: public static int add(int a,int b){ System.out.println(a+b); }
C: public static boolean isPass(int x){ if (x>80){
return true;
}
return false;
}
D: public static void print(int n){ return n;
}
A: static void show(String name){ System.out.println(name);
}
B: public static int add(int a,int b){ System.out.println(a+b); }
C: public static boolean isPass(int x){ if (x>80){
return true;
}
return false;
}
D: public static void print(int n){ return n;
}
举一反三
- 以下静态方法定义中错误的是() A: public static void sayHello(){ System.out.println("hello"); } B: public staticvoid sayHello(){ System.out.println("hello"); return; } C: public static show(String name){<br> System.out.println(name); } D: public staticboolean shiPengyou(){ return true; }
- 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 Test { public static void main(String[] args) { int a=1,b[]={2}; add(a); add(b); System.out.println(a+","+b[0]); } static int add(int x){ x++; return x; } static void add(int[] x){ x[0]++; } }
- class Demo{ public static void main(String[] args){ int x = 0; try{ x = div(1,2); }catch(Exception e){ System.out.println(e); } System.out.println(x) ; } public static int div(int a,int b){ return 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); } }