下列代码运行的结果是public class Method{public void print(){System.out.print("Hello"+",");}public void my(){System.out.println("My name is Tom.");}public static void main(String args[]){Method method=new Method();method.print();System.out.println("My name is Peter."}}
A. Hello,My name is Tom.
B. Hello,My name is Peter.
C. Hello,My name is Peter.My name is Tom.
D. My name is Peter.
查看答案
下列语句的执行结果为public class Method{private String mySelf(){String name="Tom";String mySelf="我的英文名叫"+name;return mySelf;}public static void main(String args[]){Method method=new Method();method.mySelf();}}
A. 运行异常
B. 运行错误
C. 我的英文名叫Tom
D. 什么都不输出
下面这段程序的执行结果为public class Method{public void sum(int a,int b,int c){int sum=a+b=以;System.out.println("a+b+c="+sum);}public static void main(String args[]){Method method=new Method();method.sum(12,4,0);}}
A. 12
B. a+b+c=12
C. a+b+c=16
D. 16
已知如下代码,则位置(1)处正确的方法调用代码为public class MethodDemo{public void display(int[] a){System.out.println("打印数组");}public static void main(String args[]){int[] arr={1,2,3,4,5};MethodDeom method=new MethodDemo();//(1)方法调用}}
A. method.display(arr);
B. method.display(arr[0]);
C. method.display(a);
D. method.display(a[0])
已知方法的定义形式如下:public void plus(int a,int b){}下列选项中哪个是合法的重载方法
A. public int plus(int a){}
B. public int plus1(int m,int n){}
C. public void plus(int x,int y){}
D. public int plus(int a,int b){}