使用java完成以下要求
发布网友
发布时间:2022-06-01 02:13
我来回答
共2个回答
热心网友
时间:2023-11-11 16:01
Student类
class Student {
private String name ;
private int age ;
public void speak(){
System.out.println("学生的姓名为:"+name );
System.out.println("学生的年龄为:"+age );
}
public void setName(String name){
this.name = name;
}
public int getName(){
return name;
}
public void setAge(int age){
this.age = age ;
}
public int getAge(){
return age ;
}
}
main 方法
public static void main(String[] args) {
SmsServie sms = new SmsServie();
try {
Student s1 = new Student();
s1.setName("张飞");
s1.setAge(22);
s1.speak();
Student s2 = new Student();
s2.setName("关羽");
s2.setAge(25);
s2.speak();
Student s3 = new Student();
s3 = s2 ;
s3.speak();
}
java 是一门不错的语言,同学也要努力学习 ,一起努力喔
热心网友
时间:2023-11-11 16:02
public static class Student{
private String name;
private int 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;
}
public void speak(){
System.out.println("姓名:" + name + ", 年龄:" + age);
}
public static void main(String[] args) {
Student s1=new Student();
s1.setName("张飞");
s1.setAge(22);
s1.speak();
Student s2=new Student();
s2.setName("关羽");
s2.setAge(25);
s2.speak();
Student s3=new Student();
s3.setName(s2.getName());
s3.setAge(s2.getAge());
s3.speak();
}
}