java定义个类,类有若干成员变量以及若干成员方法,然后创建一个主程序调用这个类的对象并实现所有的方法

2025-01-31 06:25:52
推荐回答(1个)
回答1:

public class Book {

private int no;
private String name;
private double value;

public Book() {
}

public Book(int no, String name, double value) {
this.no = no;
this.name = name;
this.value = value;
}

public double getValue() {
return value;
}

public void setValue(double value) {
this.value = value;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public int getNo() {
return no;
}

public void setNo(int no) {
this.no = no;
}

public String toString() {
return "no :" + no + " name :" + name + " value:" + value;
}
}

class Test {

public static void main(String args[]) {
Book book = new Book();
book.setNo(1);
book.setName("西游记");
book.setValue(22);
System.out.println(book.toString());
}
}