实训
package bbb; class Monkey { Monkey() { } Monkey(String s) { } public void speak() { System.out.println("yiyiyaya...."); } public void think() { // TODO 自动生成的方法存根 } } class people extends Monkey { public people() { super(); } public void speak() { System.out.println("小样!"); } public void think() { System.out.println("别说话 ,认真思考!"); } } public class ccc { public static void main(String [] argc) { people p = new people(); people pt = new people(); p.speak(); pt.think(); } }
1 package bbb; 2 class rectangle 3 { 4 protected int w; 5 protected int h; 6 public void setw(int w) 7 { 8 this.w = w; 9 } 10 11 public void seth(int h) 12 { 13 this.h = h; 14 } 15 16 public int crectangle() 17 { 18 return this.w*h; 19 } 20 } 21 22 class cuboid extends rectangle 23 { 24 private int l; 25 public void setl(int l) 26 { 27 this.l = l; 28 } 29 public int crectangle() 30 { 31 return this.w*h*l; 32 } 33 34 } 35 public class mathtest { 36 37 public static void main(String[] args) { 38 // TODO 自动生成的方法存根 39 rectangle m = new 40 } 41 42 }