类Person中需要定义构造方法来初始化对象,下列构造方法正确的是( )
A: public static void Person(){}
B: public void Person(){}
C: public void person(){}
D: public Person(){}
A: public static void Person(){}
B: public void Person(){}
C: public void person(){}
D: public Person(){}
举一反三
- (6-6)在类Person中定义了如下方法say(), Person类中的 ()方法能正确调用say()方法。 class Person{ public static void say(){} }
- 在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 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); } }
- 阅读下列的程序 class Person{ static{ System.out.println("static") } Person(){ System.out.println("构造") } } class Demo{ public static void main(String[] args){ Person p = new Person(); } } 下列选项中,程序的运行结果是()
- 请阅读下面的程序代码,选择正确的运行结果 Class Person{ void say(){ System.out.println(“hello”); } } class Example{ public static void main(String[] args){ Person p2 = new Person(); Person p1 = new Person(); p1.say(); p2.say();} }