"
?123456789101112131415161718package test; public class mians { public static void main(String【】 args) { // TODO Auto-generated method stub Car r=new Car(""大众"",""红色"",20); r.setBrand(""宝马""); r.run(); Vehicle s=new Vehicle(); s.brand=""Honda""; s.coulor=""red""; s.speed=30; s.run(); s.loader=2; } }
?123456789101112131415161718192021222324252627282930313233343536package test; public class Car { String brand; String coulor; double speed; public Car(String brand, String coulor, double speed) { super(); this.brand = brand; this.coulor = coulor; this.speed = speed; } public String getBrand() { return brand; } public void setBrand(String brand) { this.brand = brand; } public String getCoulor() { return coulor; } public void setCoulor(String coulor) { this.coulor = coulor; } public double getSpeed() { return speed; } public void setSpeed(double speed) { this.speed = speed; } public void run(){ //代码效果参考:https://v.youku.com/v_show/id_XNjQwNTg3MTg2MA==.html
System.out.println(coulor+brand+""开到了""+speed); } }?1234567package test; public class Vehicle extends happy{ int loader; }
?1234567891011121314package test; public class happy { String brand; String coulor; double speed; public void run(){ System.out.println(coulor+brand+""速度为""+speed); } }
2.
?123456789101112131415161718192021package hhhhkj; 2 3 public abstract class Shape { 4 protected double area; 5 protected double per; 6 protected String color; 7 8 public Shape() { 9 }1011 public Shape(String color) {12 this.color = color;13 }1415 public t void getArea();1617 public void getPer();1819 public void showAll();2021 }
?123456789101112131415161718192021222324252627282930package hhhhkj; 2 3 public class Rectangle extends Shape { 4 double //代码效果参考:https://v.youku.com/v_show/id_XNjQwNjU1NjIwOA==.html
width; 5 double height; 6 7 public Rectangle() { 8 } 910 public Rectangle(double width, double height, String color) {11 super();12 this.width = width;13 this.height = height;14 this.color = color;15 }1617 public void getArea() {18 area = width height;19 }2021 public void getPer() {22 per = (width + height) 2;23 }2425 public void showAll() {26 System.out.println(""矩形的面积为:"" + area + "",矩阵的周长为:"" + per + "",颜色为:"" + color);27 28 }?1234567891011121314151617package hhhhkj; 2 3 public class ceshilei { 4 5 public static void main(String【】 args) { 6 // TODO Auto-generated method stub 7 Shape a = new Circle(4, ""紫色""); 8 Shape b = new Rectangle(1, 6, ""
"