标签:setname out ring java 使用 方法 new name pre
简单java类开发一般原则:
class Book { private String name; private int price; private int num; public Book() { } public Book(String na ,int pri, int n) { name = na; price = pri; num = n; } public book() { } public void setName(String n) { name = n; } public void setPrice(int p) { price = p; } public void setNum(int n) { num = n; } public String getName() { return name; } public int getPrice() { return price; } public int getNum() { return num; } public int getMonney(int price, int num) { return price*num; } public String getinfo() { return "书名:"+name+"\n"+ "单价:"+price+"\n"+ "数量:"+num+"\n"; } } public class test2 { public static void main(String args[]) { Book monney = new Book("老人与海",20,3); System.out.println(monney.getinfo()); } }
标签:setname out ring java 使用 方法 new name pre
原文地址:https://www.cnblogs.com/xhnxhnu/p/9119617.html