下列描述中,()不是方法重载。
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){}
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){}
举一反三
- 下列( )方法定义和调用的代码是正确的。 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);
- 下列程序的运行结果是( )class Demo{private String name;Demo(String name){this.name = name;}private static void show(){System.out.println(name)}public static void main(String[] args){Demo d = new Demo(“lisa”);d.show();}}
- 在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); }}
- 分析下面的程序,输出的结果是? 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 ; } }
- 以下代码执行后的结果是: public class Person { String name = “小芳”; public Person(String name) { name = “小兰”; } public void show() { this.name = “小翠”; } public static void main(String[] args) { Person p = new Person(“小凤”); System.out.print(p.name); p.show(); System.out.print(p.name); } }