class Student{ private String name; private int age; private double cj; public void setName(String name){ this.name = name; } public String getName(){ return name; } public void setAge(int age){ this.age = age; } public int getAge(){ return age; } public void setCj(double cj){ this.cj = cj; } public double getCj(){ return cj; } public class Test{ public static void main(String args[]){ Student s = new Student(); s.setName("菠萝吹雪"); s.setAge(20); s.setCj(100); System.out.println(s.getName()); System.out.println(s.getAge()); System.out.println(s.getCj()); } } }
时间: 2024-02-14 21:16:46 浏览: 142
这段代码与前面的代码相比,只有一个小错误,即没有正确关闭Student类的大括号。应该将Test类的大括号放在Student类的后面,如下所示:
```java
class Student{
private String name;
private int age;
private double cj;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public void setAge(int age){
this.age = age;
}
public int getAge(){
return age;
}
public void setCj(double cj){
this.cj = cj;
}
public double getCj(){
return cj;
}
}
public class Test{
public static void main(String args[]){
Student s = new Student();
s.setName("菠萝吹雪");
s.setAge(20);
s.setCj(100);
System.out.println(s.getName());
System.out.println(s.getAge());
System.out.println(s.getCj());
}
}
```
除此之外,这两段代码没有任何区别。
阅读全文