声明一个图书类(Java)

时间:2025-03-10 16:15:16
class Library{ String name; //书名 static int num=0; //编号 float price; //int sum=0; static int cbook=0;//册数 static int zcbook=0;//总册数 public Library(String name,float price, int cbook) { =name; =price; =cbook; =zcbook+cbook; } public void print() { ("书名: " + name + " 编号: "+ num + " 价格: " + price + " 册数: " + cbook); num=num+cbook; } public void z(){ ("\n" + "总册书为:" + zcbook); } } public class t9 { public static void main(String[] args) { // TODO Auto-generated method stub Library book1 = new Library("Java开发实战经典",100.8f,10); (); Library book2 = new Library("Java大学实用教程",60.5f,4); (); Library book3 = new Library("名侦探柯南",78.0f, 6); (); Library book4 = new Library("JavaEE基础实用教程",36.7f,10); (); (); } }