Java語言類的特性-創(chuàng)新互聯(lián)

本周學(xué)了關(guān)于Java語言類的特性,了解了類的私有成員與公共成員、方法的重載、構(gòu)造方法、靜態(tài)成員、對象的應(yīng)用以及基本類型與包裝類類型之間的自動轉(zhuǎn)換。

在凌源等地區(qū),都構(gòu)建了全面的區(qū)域性戰(zhàn)略布局,加強(qiáng)發(fā)展的系統(tǒng)性、市場前瞻性、產(chǎn)品創(chuàng)新能力,以專注、極致的服務(wù)理念,為客戶提供成都做網(wǎng)站、成都網(wǎng)站制作 網(wǎng)站設(shè)計制作按需開發(fā),公司網(wǎng)站建設(shè),企業(yè)網(wǎng)站建設(shè),成都品牌網(wǎng)站建設(shè),成都營銷網(wǎng)站建設(shè),成都外貿(mào)網(wǎng)站建設(shè)公司,凌源網(wǎng)站建設(shè)費用合理。

做了一下實驗,實驗內(nèi)容如下:
(1)創(chuàng)建一個 Rectangle 類,添加 width 和 height兩個成員變量(要求 private 類型)。
(2)在 Rectangle 中添加兩種方法分別計算矩形的周長和面積。
(3)分別添加無參和有參構(gòu)造方法,用于給成員變量初始化。
(4)添加方法 show (),用于輸出成員變量的值。
(5)聲明靜態(tài)方法 static void count ()用于統(tǒng)計創(chuàng)建的對象個數(shù)。
(6)聲明方法 Rectangle compare(Rectangle),要求根據(jù)面積比較對象的大小。
(7)編寫 main()方法,在該方法中創(chuàng)建 Rectangle 類對象,并分別調(diào)用類方法。

package 實驗;
class Rectangle{
private int width;
private int height;
private static int num=0;
public Rectangle(int w,int h) {
this.width=w;
this.height=h;
num++;
}
public static void count() {
System.out.println("創(chuàng)建了"+num+"個對象");
}
public void show() {
System.out.print("寬:"+width);
System.out.println("高:"+height);
}
double C() {
return width+height;
}
double ?S() {
return width*height;
}
public Rectangle compare(Rectangle p) {
if(this.width*height>p.width*height)
return this;
else
?return p;
}?
}
public class 實驗五 {
public static void main(String[] args) {
// TODO Auto-generated method stub
Rectangle a,b;
a=new Rectangle(4,8);
b=new Rectangle(3,5);
Rectangle.count ();
a.show();
System.out.println("矩形1的周長為:"+a.C());
System.out.println("矩形1的面積為:"+a.S());
b.show();
System.out.println("矩形2的周長為:"+b.C());
System.out.println("矩形2的面積為:"+b.S());
var S3=a.compare(b);
if(S3==a)
?System.out.println("矩形1的面積大");
else
?System.out.println("矩形2的面積大");?
}
}

你是否還在尋找穩(wěn)定的海外服務(wù)器提供商?創(chuàng)新互聯(lián)www.cdcxhl.cn海外機(jī)房具備T級流量清洗系統(tǒng)配攻擊溯源,準(zhǔn)確流量調(diào)度確保服務(wù)器高可用性,企業(yè)級服務(wù)器適合批量采購,新人活動首月15元起,快前往官網(wǎng)查看詳情吧

網(wǎng)站題目:Java語言類的特性-創(chuàng)新互聯(lián)
鏈接URL:http://muchs.cn/article28/dhdhcp.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供小程序開發(fā)面包屑導(dǎo)航、App設(shè)計外貿(mào)建站、關(guān)鍵詞優(yōu)化建站公司

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作