Java语言 The Blacks! ver.1.1

	public static void main(String[] args) {
		// TODO 自动生成的方法存根
		System.out.println("The Blacks! ver.1.1");
		
		father f1 = new father();
		f1.show();
		f1.name(); f1.age(); 
		
		mother m1 = new mother();
		m1.name(); m1.age();
		
		son s1 = new son();
		s1.children();		
		s1.name(); s1.age(); 
		
		daughter d1 = new daughter();
		d1.children();
		d1.name(); d1.age();
	}
}

interface people {
	
	 void name();
	 
	 void age();
	 
}

class father
	implements people {
	
	private String fatherhaircolor = "yellow";
	
	public String getfatherHaircolor() {
		return fatherhaircolor;
	}
	
	public String familyname() {
		String familyname = "Black";
		return familyname ;
	}
		public void age() {
			System.out.println("I am 30 years old.");
		}
		
		public void name() {
			System.out.println("My name is Jack,Jack"+" "+this.familyname());
		}
	
		public void show() {
			System.out.println("Ah,hello.");
		}

}

class mother extends father{
	
	private String motherhaircolor = "black";
	
	public String getmotherhaircolor() {
		return motherhaircolor;
	}

	public mother () {
		System.out.println("Ya ha lo!!");
	}
	
	
	public void age() {
		System.out.println("I am 27 years old.");
	}
	
	public void name() {
		System.out.println("My name is Jenny,Jenny"+" "+this.familyname());
	}
	
}


abstract class mychildren extends mother{
	
   abstract  void children();
   
}

class son extends mychildren{
	public void show() {
		System.out.println("Hi!");
	}
	
	public void children() {
		System.out.println("I have "+this.getmotherhaircolor()+" hair.");
	}
	
	public void name() {
		System.out.println("My name is Tom,Tom"+" "+this.familyname());
	}
	
	public void age() {
		System.out.println("I am 6 years old.");
	}
}

class daughter extends mychildren{
	public daughter() {
		System.out.println("Hh,hello...");
	}
	public void children() {
		
		System.out.println("I have "+this.getfatherHaircolor()+" hair.");
	}
	
	public void name() {
		System.out.println("My name is Penny,Penny"+" "+this.familyname());
	}
	
	public void age() {
		System.out.println("I am 6 years old too.");
	}
}

运行结果:

The Blacks! ver.1.1
Ah,hello.
My name is Jack,Jack Black
I am 30 years old.
Ya ha lo!!
My name is Jenny,Jenny Black
I am 27 years old.
Ya ha lo!!
I have black hair.
My name is Tom,Tom Black
I am 6 years old.
Ya ha lo!!
Hh,hello...
I have yellow hair.
My name is Penny,Penny Black
I am 6 years old too.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值