package?cn.book;
成都創(chuàng)新互聯(lián)專注于阿榮網(wǎng)站建設(shè)服務(wù)及定制,我們擁有豐富的企業(yè)做網(wǎng)站經(jīng)驗(yàn)。 熱誠為您提供阿榮營銷型網(wǎng)站建設(shè),阿榮網(wǎng)站制作、阿榮網(wǎng)頁設(shè)計、阿榮網(wǎng)站官網(wǎng)定制、微信小程序開發(fā)服務(wù),打造阿榮網(wǎng)絡(luò)公司原創(chuàng)品牌,更為您提供阿榮網(wǎng)站排名全網(wǎng)營銷落地服務(wù)。
public?class?Book?{
private?String?auther="吳承恩";
private?String?name="西游記";
private?String?number="1";
private?double?price=100;
public?String?getAuther()?{
return?auther;
}
public?void?setAuther(String?auther)?{
this.auther?=?auther;
}
public?String?getName()?{
return?name;
}
public?void?setName(String?name)?{
this.name?=?name;
}
public?String?getNumber()?{
return?number;
}
public?void?setNumber(String?number)?{
this.number?=?number;
}
public?double?getPrice()?{
return?price;
}
public?void?setPrice(double?price)?{
this.price?=?price;
}
@Override
public?String?toString()?{
return?"?作者:"?+?auther?+?",?書名:"?+?name?+?",?書號:"?+?number?+?",?價格:"?+?price?;
}
//可以從這調(diào)用get?set?方法?設(shè)置屬性
public?static?void?main(String[]?args)?{
Book?book?=?new?Book();
System.out.println(book.toString());
}
}
首先,對象數(shù)組:
人類:
public class Person {
//定義Person類的屬性
public int age;
public String name;
//構(gòu)造方法
public Person(int age,String name){
this.age = age;
this.name = name;
}
}
測試類:
public class Test {
public static void main(String[] args) {
//實(shí)例化一個對象數(shù)組
Person[] p = new Person[3]; //{new Person(23,"孫港"),new Person(24,"王悅"),new Person(25,"王芳")}
p[0] = new Person(32,"sg");
p[1] = new Person(24,"王悅");
p[2] = new Person(25,"王芳");
//循環(huán)輸出對象數(shù)組
for(int i = 0;ip.length;i++){
System.out.println("age屬性是:"+p[i].age+",name屬性是:"+p[i].name);
}
}
}
只是把傳入的參數(shù)變成了傳數(shù)組。希望可以幫到你!
package com.hua.excep;
public class Libary {
private int id;
private String name;
private String shop;
private int num;
//兩個構(gòu)造方法
//無參
public Libary() {
}
//四個參數(shù)
public Libary(int id, String name, String shop, int num) {
this.id = id;
this.name = name;
this.shop = shop;
this.num = num;
}
//輸入圖書信息
public void inputBook(int id,String name,String shop){
this.id=id;
this.name=name;
this.shop=shop;
}
//輸出三個圖書信息
public int getId() {
return id;
}
public String getName() {
return name;
}
public String getShop() {
return shop;
}
//修改庫存
public void setNum(int num) {
this.num = num;
}
}
網(wǎng)站名稱:java圖書類代碼 java圖書系統(tǒng)源代碼
當(dāng)前地址:http://vcdvsql.cn/article6/doisiig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣、響應(yīng)式網(wǎng)站、建站公司、動態(tài)網(wǎng)站、網(wǎng)站收錄、定制開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)