实现一个类Single,包含:一个成员变量x,构造方法,重写toString,测试类
时间: 2023-05-28 17:01:53 浏览: 166
public class Single {
private int x;
public Single(int x) {
this.x = x;
}
public int getX() {
return x;
}
public void setX(int x) {
this.x = x;
}
@Override
public String toString() {
return "Single [x=" + x + "]";
}
}
//测试类
public class SingleTest {
public static void main(String[] args) {
Single s = new Single(10);
System.out.println(s);
}
}
阅读全文