阅读下面代码段:public class Test{ public static void main(String args[]){ char ch; switch(ch) { case’a’:System.out.print("abc");break; case’b’:System.out.print("ab"); case’c’:System.out.print("c");break; default:System.out.print("abc"); } }}不输出"abc"的ch值是 ( )
A: ’a’
B: ’b’
C: ’c’
D: ’d’
A: ’a’
B: ’b’
C: ’c’
D: ’d’
举一反三
- 下列程序运行的结果是______。 public class Example{ String str=new String("good"); char[]ch={’a’,’b’,’c’}; public static void main(String args[]){ Example ex=new Example(); ex.change(ex.str,ex.ch); System.out.print(ex.str+" and "); System.out.print(ex.ch); } public void change(String str,char ch[]){ str="test ok"; ch[0]=’g’; } A: good and abc B: good and gbc C: test ok and abc D: test ok and gbc
- import java.io.*; class Person{ public void print(){System.out.print("Person ");} public void printMyGender(String s){ this.print(); System.out.print(s+" "); } } class Gender{ String type="gender"; public void print(Person p){p.printMyGender(type);} } class Female extends Gender{ public Female(){ type="female"; } } class Male extends Gender{ public Male(){ type="male"; } } class Employee extends Person{ public void print(){ System.out.print("Employee ");} } class Manager extends Employee{ public void print(){ System.out.print("Manager ");} } public class Test{ public static void main(String[] args){ Manager man = new Manager(); Employee em = new Employee(); Gender gender1 = new Male(); Gender gender2 = new Female(); gender1.print(man); gender2.print(em); } } 对于以上代码,其运行结果是
- 给定以下代码,程序的运行结果是 ()public class Example {String str=new String("good");char [] ch={'a','b','c'};public static void main(String[] args) {Example ex=new Example();ex.change(ex.str, ex.ch);System.out.print(ex.str+"and");System.out.print(ex.ch);}public void change(String str,char ch[]){str="test ok";ch[0]='g';}} A: goodandabc B: goodandgbc C: test okandabc D: test okandgbc
- 下列程序的输出结果是()。 using System; class Program { public static void Main(string[] args) { int x=1,a=0,b=0; switch(x) { case 0: b++; break; case 1: a++; break; case 2: a++; b++; break; } Console.WriteLine(“a={0},b={1}”,a,b); } }
- 中国大学MOOC: 下列代码中构造方法的返回类型是()public class Village { Village () { System .out .println(“hiding in Village”) ; } public static void main( String args [ ]) { Village c =new Village ( ) ;}class Village { public static void main( String args [ ]) { Village c =new Village ( ) ; } Village () { System .out .println(“hiding in Village”) ; } }