class Student{ String name; int age; int score=88; Student(String a1, int a2, int a3){ name=a1; age=a3; score=a2; } } 在使用该类时,已使用下面语句生成了该类的对象: Student s1,s2; s1=new student("张三",20,33); s2=new student(); 问题: 1)s1.name,s1.age,s1.score的值各是什么? 2)s2.name,s2.ag
时间: 2024-04-09 09:32:18 浏览: 99
1) 对象s1的属性值为:
- s1.name = "张三"
- s1.age = 33
- s1.score = 20
2) 对象s2的属性值为:
- s2.name = null (未赋值)
- s2.age = 0 (默认值)
- s2.score = 88 (默认值)
相关问题
n 编写一个Student类,包含name、gender、age、id、score属性,分别为String、String、int、int、double类型。 n 类中声明一个say方法,返回St
编写一个Student,包含name、gender、age、idscore属性,分别为String、String、int、int、double类型。
```java
public class Student {
String name;
private String gender;
private int age;
private int id;
private double score;
public Student name, String gender, int age, int id, double score) {
this.name = name;
this.gender = gender this.age = age;
this.id =;
this.score = score;
}
public String getName() {
return name;
}
public String getGender {
return gender;
}
public int getAge() {
return age;
}
public int getId() {
return id;
}
public double getScore() {
return score;
}
public void say() {
System.out.println("I am a student.");
}
}
```
阅读全文