freepeople性欧美熟妇, 色戒完整版无删减158分钟hd, 无码精品国产vα在线观看DVD, 丰满少妇伦精品无码专区在线观看,艾栗栗与纹身男宾馆3p50分钟,国产AV片在线观看,黑人与美女高潮,18岁女RAPPERDISSSUBS,国产手机在机看影片

正文內(nèi)容

java習(xí)題解答-資料下載頁(yè)

2025-03-27 23:37本頁(yè)面
  

【正文】 er。 public void gotOn(int n){ passenger = passenger+n。 (The person on bus is:+passenger)。 } public void gotOff(int n){ passenger = passengern。 (The person on bus is:+passenger)。 }}public class BusTest{ public static void main(String []args){ Bus bus = new Bus()。 ()。 (60)。 ()。 (10)。 (5)。 }}30. 參考程序如下:public abstract class Shape{ private String name。 public Shape(){} public Shape(String name){ = name。} public void setName(String name){ = name。 } public String getName(){ return name。 } public abstract double perimeter()。 public abstract double area()。}public class Triangle extends Shape{double a,b,c。public Triangle(){ = 0。 = 0。 = 0。}public Triangle(double a, double b, double c){ = a。 = b。 = c。}public double area(){ double s = (a + b + c) / 。 return (s * (sa) * (sb) * (sc))。}public double perimeter(){ return a + b + c。}public static void main(String[] args){ Triangle ta = new Triangle(3, 4, 5)。 (())。}}31. 參考程序如下:public class Cuboid extends Rectangle{ private double height。 public Cuboid(double length,double width, double height){ super(length,width)。 = height。 } public Cuboid(){ this(0,0,0)。 } public void setHeight(double height){ = height。 } public double getHeight(){ return height。 } public double volume(){ return area() * height。 }}public class CuboidTest{ public static void main(String[]args){ Cuboid cb = new Cuboid()。 (10)。 (5)。 (2)。 (volume=+())。 }}32. 參考程序如下:public abstract class CompareObject{public abstract int pareTo(Object obj)。}public class Position extends CompareObject{ private int x。 private int y。 public Position(){} public Position(int x, int y){ = x。 = y。}public void setX(int x){ = x。 }public void setY(int y){ = y。}public int getX(){return x。}public int getY(){return y。} //實(shí)現(xiàn)pareTo()方法 public int pareTo(Object obj){ Position pos = (Position)obj。double dist1 = (x*x + y*y)。 double dist2 = ( * + * )。 return (int)(dist1dist2)。} public static void main(String[]args){ Position pos1 = new Position(0,0)。 Position pos2 = new Position(3,4)。 ((pos2))。 }}33. 參考程序如下:import 。public class MyDate { private int year。 private int month。 private int day。 public MyDate() { year = 1970。 month = 1。 day = 1。 } public MyDate(int year,int month,int day){ = year。 = month。 = day。 } public int getYear(){ return year。} public int getMonth(){ return month。 } public int getDay(){ return day。 } public boolean eauals(Object obj){ MyDate md = (MyDate)obj。 if(== amp。amp。 == amp。amp。 == ) return true。 else return false。 } public int pareTo(MyDate md){ //這里使用Date類(lèi)計(jì)算兩個(gè)日期差的天數(shù) Date d = new Date(year,month,day)。 Date d2 = new Date(,)。 long days =(()())/1000/60/60/24。 return (int)days。 } public static void main(String []args){ MyDate md1 = new MyDate(2007,12,20)。 MyDate md2 = new MyDate(2008,12,20)。 ((md1))。 } } 34. 答:(1)① ⑤ (2)② ⑤(3)① 3 ② 5 ③ 無(wú) ④ 4 ⑤ 無(wú) ⑥ 535. 答:設(shè)汽車(chē)Auto定義為抽象類(lèi),玩具Toy定義為接口,玩具汽車(chē)ToyAuto定義為具體類(lèi)。飛機(jī)Plane定義為抽象類(lèi),玩具飛機(jī)ToyPlane定義為具體類(lèi),阿帕奇直升機(jī)ApacheHelicopter定義為具體類(lèi)。代碼如下:// 汽車(chē)類(lèi)的定義public abstract class Auto{}// 玩具接口的定義public interface Toy{}// 玩具汽車(chē)的定義public class ToyAuto extends Auto implements Toy{}// 飛機(jī)類(lèi)的定義public abstract class Plane{}// 玩具飛機(jī)的定義public class ToyPlane extends Plane implements Toy{}// 阿帕奇直升機(jī)的定義public class ApacheHelicopter extends Plane{}36. 參考程序:public enum TrafficLight{GREEN, RED, YELLOW。public static void main(String[]args){ TrafficLight[] tl = ()。 for(TrafficLight light:tl){ (light)。 ( +())。}TrafficLight red = 。switch(red){ case RED: (RED, stop.)。 break。case GREEN: (GREEN, go.)。 break。case YELLOW: (YELLOW, do not know.)。 break。}}}37. 答:注解類(lèi)型的定義如下。public @interface Author{ String name()。String date()。}38. 參考程序如下:public interface Flyable{ public abstract void takeoff()。 public abstract void land()。 public abstract void fly()。 } public abstract class Vehicle {} public abstract class AirPlane extends Vehicle implements Flyable{ public void takeoff(){ (Plane takeoff.)。} public void land(){ (Plane land.)。} public void fly(){ (Plane flying.)。}} public abstract class Animal{ public abstract void eat()。} public class Bird extends Animal implements Flyable{ public void takeoff(){ (Bird takeoff.)。} public void land(){ (Bird land.)。} public void fly(){ (Bird flying.)。}public void eat(){ (Bird eating.)。}public void buildNest(){ (Bird buiding nest.)。}public void layEggs(){ (Bird lying eggs.)。}} public class Superman extends Animal implements Flyable{ public void takeoff(){ (Superman takeoff.)。} public void land(){ (Superman land.)。} public void fly(){ (Superman flying.)。}public void eat(){ (Superman eating.)。}public void leapBuiding(){ (Superman leap building.)。}public void stopBullet(){ (Superman stop bullet.)。}}public class PolymorphismDemo{ public static void main(String []args){ Flyable plane = new AirPlane()。 ()。 ()。 Flyable bird = new Bird()。 ()。 ()。 // 編譯錯(cuò)誤}}39. 答:(1)若將樂(lè)器都定義為類(lèi),則子類(lèi)可以繼承或覆蓋超類(lèi)中的方法。(2)若將Instrument定義成抽象類(lèi),則子類(lèi)需要實(shí)現(xiàn)Instrument類(lèi)的方法。(3)若將Instrument定義為接口,Wind定義為抽象類(lèi),其他定義為具體類(lèi)。實(shí)現(xiàn)代碼如下:public interfac
點(diǎn)擊復(fù)制文檔內(nèi)容
環(huán)評(píng)公示相關(guān)推薦
文庫(kù)吧 www.dybbs8.com
備案圖鄂ICP備17016276號(hào)-1