1)运行下面一段代码,能正确输出的是(C)。(选择两项)
A: A.int age=20;string name=”如花”;
Console.write(“姓名”+name+”年龄”+age);
B: B.int age=20;string name=”如花”;
Console.write(“姓名{0},年龄为{1}”,name,age);
C: C.int age=20;string name=”如花”;
Console.write(name,age);
D: D.int age;string name;
Console.write(“姓名”+name+”年龄”+age);
A: A.int age=20;string name=”如花”;
Console.write(“姓名”+name+”年龄”+age);
B: B.int age=20;string name=”如花”;
Console.write(“姓名{0},年龄为{1}”,name,age);
C: C.int age=20;string name=”如花”;
Console.write(name,age);
D: D.int age;string name;
Console.write(“姓名”+name+”年龄”+age);
举一反三
- 下列( )方法定义和调用的代码是正确的。 A: static void Introduce(string gender = "男", string name, int age = 18){} Introduce(name: "alex", age: 20); B: static void Introduce(string name, int age = 18, string gender = "男"){} Introduce(age: 20, name: "alex"); C: static void Introduce(string gender = "男", string name, int ago = 18){} Introduce(age: 20, name: "alex"); D: static void Introduce(string name, int age = 18, string gender = "男"){}Introduce(name: "alex", age: 20);
- 【填空题】public class ThisTest{ private String name; private int age; public ThisTest() { System.out.println("产生一个新的Person对象。"); } public ThisTest (String name, int age) { this(); this.name = name; this.age = age; } public String getInf() { return "姓名:" + name + ",年龄:" + age; } public static void main(String[] args) { ThisTest per = new ThisTest("张三", 20); System.out.println(per.getInf()); } } 运行结果为:____
- 分析下面的程序,输出的结果是? public class Test { public static void main(String[] args) { final Person p = new Person("张三", 23); p.setName("李四"); p.setAge(24); System.out.println(p); } } class Person { private String name; private int age; public Person() { super(); } public Person(String name, int age) { super(); this.name = name; this.age = age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public int getAge() { return age; } public void setAge(int age) { this.age = age; } @Override public String toString() { return "我的姓名是:" + name + ",我的年龄是:" + age ; } }
- 在C#中,下列结构或者类定义正确的是(选一项) A: public struct Person{ string name; int age; public void ShowName(){ Console.WriteLine(name); }} B: public struct Person{ string name; int age; public Person(){ Conssole.WriteLine(name); }} C: public class Person{ string name; int age; public Person(){ Conssole.WriteLine(name); }} D: public class Person{ string name; int age; public Person(string name){ Conssole.WriteLine(name); }}
- 下列描述中,()不是方法重载。 A: void Show(){}和void Show(string name){} B: string Show(string name){}和void Show(string name){} C: string Show(int age){}和void Show(string name){} D: void Show(int age){}和void Show(int age,string name){}