Java個別關鍵字

2021-08-31 20:57:09 字數 2979 閱讀 4746

package 自主練習;

final class animal

class dog extends animal

public class final關鍵字修飾類

}

在這裡插入**片

package 自主練習;

final class animal }

class dog extends animal

}public class final關鍵字修飾方法

}

package 自主練習;

class student

public class static關鍵字靜態變數

package 自主練習;

public class 靜態**塊

public static void main(string args) }

class person

}

package 自主練習;

public class super關鍵字 class dog extends animal

void printname()

public static void main(string args)
private

string number;

private string name;

private string publisher;

private string author;

public void book(string number, string name, string publisher, string author)

public string getnumber()

public void setnumber(string number)

public string getname()

public void setname(string name)

public string getpublisher()

public void setpublisher(string publisher)

public string getauthor()

public void setauthor(string author)

public string tostring()

public double getheight()

public double getwidth()

public double thickness()

public boolean getfull()

public void setheight(double height)

public void setwidth(double width)

public void setthickness(double thickness)

public void setfull1(boolean full)

public string tostring()

public static void main(string args)

public string getname()

public int getage()

public int getmage()

public string tostring()

public class kennel

}}

private double diameter;

public void sphere()

this.diameter=1.0;

public void sphere(double d)

this.diameter=d;

public void setdameter(double d)

this.diameter=d;

public double getdiameter()

return this.diameter;

public double volume()

return

4math.pimath.pow(this.diameter/2,3)/3;

public double area()

return 4math.pimath.pow(this.diameter/2,2);

public string tostring()

string out =「該球體的直徑為:」+ this.diameter+"\n"+

「該球體的表面積為:」+this.area() + 「\n」 +

「該球體的體積為:」+ this.volume();

return out;

public static void main(string args)

scanner scan= new scanner(system.in);

sphere sphere1 = new sphere();

sphere sphere2 = new sphere();

system.out.println(「sphere1: 」+ sphere1 +」

+「\n」);

system.out. println(「sphere2: 」+ sphere2 +」

+「\n」);

system.out.println(「sphere1和sphere2分別呼叫無參構造方法」+「和帶乙個引數的構造方法進行初始化.」);

system.out.print(「現在,請輸入乙個數作為球sphere1 的直徑值」);

sphere1.setdameter(scan.nextdouble());

system.out.println("\n" + 「更改過的sphere1:」);

static關鍵字 java關鍵字

先按照宣告順序初始化基類靜態變數和靜態 塊,接著按照宣告順序初始化子類靜態變數和靜態 塊,而後按照宣告順序初始化基類普通變數和普通 塊,然後執行基類建構函式,接著按照宣告順序初始化子類普通變數和普通 塊,最後執行子類建構函式。import static com.test.test1.fu.say i...

Java的關鍵字

一 原始資料型別 byte short int long float double char boolean 二 迴圈關鍵字 do while for break continue 三 分支關鍵字 if else switch case default break 四 方法,變數和類修飾符 priv...

java關鍵字大全

abstract表明類或者成員方法具有的抽象屬性 assert用來進行程式測試 boolean基本資料型別之一,布林型 break提前跳出乙個塊 byte基本資料型別之一,位元組型 case用在switch語句中,表明其中的乙個分支 catch用在異常處理中,用來捕捉異常 char基本資料型別之一,...