class Person { String name; int age; [br][/br] public Person(String name, int age) { super(); this.name = name; this.age = age; } @Override public boolean equals(Object obj) { Person person=null; if(obj instanceof Person) person=(Person)obj; if(name.equals(person.name)&&age==person.age) return true; return false; } } class Test{ public static void main(String[] args) { Person person1 = new Person("张三", 12); Person person2 = new Person("张三", 12); System.out.println(person1.equals(person2));//运行结果是? } } 程序运行结果是什么? A: true B: false
class Person { String name; int age; [br][/br] public Person(String name, int age) { super(); this.name = name; this.age = age; } @Override public boolean equals(Object obj) { Person person=null; if(obj instanceof Person) person=(Person)obj; if(name.equals(person.name)&&age==person.age) return true; return false; } } class Test{ public static void main(String[] args) { Person person1 = new Person("张三", 12); Person person2 = new Person("张三", 12); System.out.println(person1.equals(person2));//运行结果是? } } 程序运行结果是什么? A: true B: false
给出程序的运行结果() classPerson{ Stringname; intage; Person(){ System.out.println('Person()'); } voidPerson(){ System.out.println('method()'); } publicvoidtell(){ System.out.println('姓名:'+name+',年龄:'+age); } } publicclassClassTest02{ publicstaticvoidmain(String[]args){ Personperson=newPerson(); person.name='张三'; person.age=30; person.tell(); } }
给出程序的运行结果() classPerson{ Stringname; intage; Person(){ System.out.println('Person()'); } voidPerson(){ System.out.println('method()'); } publicvoidtell(){ System.out.println('姓名:'+name+',年龄:'+age); } } publicclassClassTest02{ publicstaticvoidmain(String[]args){ Personperson=newPerson(); person.name='张三'; person.age=30; person.tell(); } }
若有:struct Person{ char name[20] ;int age ;char sex ;} a = {"Li ning", 20, 'M'};则输出结构变量 a 的 age 成员的语句为( )。 A: printf("%d", age); B: printf("%d", Person.age); C: printf("%d", a.age); D: printf("%d", Person.a.age);
若有:struct Person{ char name[20] ;int age ;char sex ;} a = {"Li ning", 20, 'M'};则输出结构变量 a 的 age 成员的语句为( )。 A: printf("%d", age); B: printf("%d", Person.age); C: printf("%d", a.age); D: printf("%d", Person.a.age);
设有一结构体类型变量定义如下: struct worker { char name[20]; char sex; int age; } person; 若对结构体变量person的年龄进行赋值,下面正确的赋值语句是________。 A: age=40; B: worker.age=40 C: person.age=40 D: worker.person.age=40
设有一结构体类型变量定义如下: struct worker { char name[20]; char sex; int age; } person; 若对结构体变量person的年龄进行赋值,下面正确的赋值语句是________。 A: age=40; B: worker.age=40 C: person.age=40 D: worker.person.age=40
在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); }}
在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); }}
class Person { int age; public Person(int age) { ______________//让局部变量的age给成员变量的age赋值 } public int getAge() { return this.age; } } 在横线处填入正确的代码,可以让局部变量的age给成员变量的age赋值
class Person { int age; public Person(int age) { ______________//让局部变量的age给成员变量的age赋值 } public int getAge() { return this.age; } } 在横线处填入正确的代码,可以让局部变量的age给成员变量的age赋值
(6-2)定义如下Person类,(1)处合理的代码是。 class Person { String name, department; int age; public Person(String n) { name = n; } public Person(String n, int a) { name = n; age = a; } public Person(String n, int a, String d) { ① department = d; } }
(6-2)定义如下Person类,(1)处合理的代码是。 class Person { String name, department; int age; public Person(String n) { name = n; } public Person(String n, int a) { name = n; age = a; } public Person(String n, int a, String d) { ① department = d; } }
已知Person类的两个对象p1,p2,类的成员变量age,name,正确说法是: A: p1,p2的成员变量在内存中共用同一存储空间 B: p1,p2有各自的内存空间,在自己的内存空间有各自的age和name空间 C: p1.age和p2.age没什么区别 D: p1和p2的age成员变量,都直接使用Person.age
已知Person类的两个对象p1,p2,类的成员变量age,name,正确说法是: A: p1,p2的成员变量在内存中共用同一存储空间 B: p1,p2有各自的内存空间,在自己的内存空间有各自的age和name空间 C: p1.age和p2.age没什么区别 D: p1和p2的age成员变量,都直接使用Person.age
分析下面的程序,输出的结果是? 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 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 ; } }
中国大学MOOC: 有如下定义:struct person{char name[9]; int age;};struct person class1[10]={
中国大学MOOC: 有如下定义:struct person{char name[9]; int age;};struct person class1[10]={