java string 类 上机_java上机试题
請將下列關鍵字填寫到適當的位置中。newextendsimplementsstaticsuperpublicabstractthisimportpackage(1)Fruits;//聲明包語句(2)java.util.*;abstractclassFruit//定義抽象類Fruit{D...
請將下列關鍵字填寫到適當的位置中。
new extends implements static super
public abstract this import package
(1) Fruits;//聲明包語句
(2) java.util.*;
abstract class Fruit //定義抽象類Fruit
{
Date produceDate;
double weight;
public Fruit(double weight) {
produceDate = (3) Date();//將produceDate設定為系統當前時間
(4) .weight = weight;//為數據成員weight賦初值
}
public (5) String getInfo();//定義抽象方法
}
interface Edible//定義接口Edible
{final int Edible_HOT = 1;
final int Edible_Cool = 2;
void howToEat(int EatMode);
}
//Apple類是Fruit的派生類并實現Edible接口
class Apple (6) Fruit (7) Edible
{
(8) int count = 0;//count負責記錄Fruit對象的數量
String color;
public Apple(double weight,String c)
{
(9) (weight);//調用父類的構造函數
color = c;
count++;
}
(10) String getInfo() //重寫抽象類中的抽象方法
{
return "produceDate=" + produceDate + " weight=" + weight + " color=" + color;
}
public void howToEat(int mode) //重寫接口中的抽象方法
{
if(mode == Edible.Edible_HOT)
System.out.println("Make apple pine!");
else
System.out.println("Make apple juice!");
}
}
class Test
{
public static void main(String [] args)
{
Apple a = new Apple(0.2,"red");
//顯示當前已創建的Apple對象數量
System.out.println("count=" + Apple.count);
System.out.println(a.getInfo());
a.howToEat(Edible.Edible_HOT);
}
}
展開
總結
以上是生活随笔為你收集整理的java string 类 上机_java上机试题的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: iPad和Mac彻底打通了 苹果产品线有
- 下一篇: 国债逆回购和国债哪个好?二者之间的区别有