java继承示例
2011-03-18 11:35 Rollen Holt 阅读(273) 评论(0) 编辑 收藏 举报1: /**
2: *3: * This program is used to test Inheritance4: * @author Rollen Holt5: */6:7: class SuperClass
8: {9: int number1;
10: int number2;
11: SuperClass(){12: number1=number2=1;13: }14: SuperClass(int temp){
15: number1=number2=temp;16: }17: SuperClass(int temp1, int temp2 ){18: number1=temp1;19: number2=temp2;20: }21: void Show(){
22: System.out.println("SupceClass");
23: System.out.println(number1);24: System.out.println(number2);25: }26: }27:28: public class Inheritance extends SuperClass {29: int number3;
30: Inheritance(){31: super();
32: number3=1;33: }34: Inheritance(int temp){
35: super(temp);
36: number3=temp;37: }38: Inheritance(int temp1, int temp2, int temp3){39: super(temp1,temp2);
40: number3=temp3;41: }42:43: void Show(){
44: super.Show();
45: System.out.println(number3);46: }47:48: public static void main(String[] args) {49: System.out.println("This program is used to test Inheritance");
50:51: SuperClass superNumber1 = new SuperClass();
52: superNumber1.Show();53:54: SuperClass superNumber2 = new SuperClass(2);
55: superNumber2.Show();56:57: SuperClass superNumber3 = new SuperClass(2,2);
58: superNumber3.Show();59:60: System.out.println("Inheritance Class");
61:62: Inheritance inher1 = new Inheritance();
63: inher1.Show();64:65: Inheritance inher2 = new Inheritance(2);
66: inher2.Show();67:68: Inheritance inher3 = new Inheritance(1,2,3);
69: inher3.Show();70:71: }72:73: }74:
==============================================================================
本博客已经废弃,不在维护。新博客地址:http://wenchao.ren
我喜欢程序员,他们单纯、固执、容易体会到成就感;面对压力,能够挑灯夜战不眠不休;面对困难,能够迎难而上挑战自我。他
们也会感到困惑与傍徨,但每个程序员的心中都有一个比尔盖茨或是乔布斯的梦想“用智慧开创属于自己的事业”。我想说的是,其
实我是一个程序员
==============================================================================
![](http://service.t.sina.com.cn/widget/qmd/1882500857/8c17d4b5/1.png)