设已定义类 MC如下,能正确实现 MC对象初始化功能的构造方法是( )。class MC{String name,num;……}
A. MC(String name,int num ){name=name;num=num;}
B. MC(String name,String num ){name=name;num=num;}
C. MC(String name,String num ){this.name=name;this.num=num;}
D. mc(String name,String num ){this.name=name;this.num=num;}
查看答案
下列方法定义中,正确的是( )。
A. public int fx( ){...}
B. public static x(int y){...}
C. public(double d){...}
D. public x( ){...}
下列代码在编译时会产生错误,下面哪种修改可以更正错误?( )class Test{private int m;public static void fun(){System.out.println(m);}}
A. 将private int m 改为protected int m
B. 将private int m 改为public int m
C. 将private int m 改为static int m
D. 将private int m 改为int m
以下代码的输出结果为( )public class Pass{static int j = 20;public void amethod(int x){x = x*2;j = j*2;}public static void main(String args[]){int i = 10;Pass p = new Pass();p.amethod(i);System.out.println(i+" and "+j);}}
A. 错误:方法参数与变量不匹配
B. 20 and 40
C. 10 and 40
D. 10 and 20
类A中构造方法的正确声明是( )
A. public A (int x) {...}
B. static A (int x) {...}
C. public a (int x) {...}
D. int A (int x) {...}