Java语言 The Blacks!ver.1.3

更新内容2020/10/31
famliyname变量变为常量,放入people接口中
在mother类中添加私有内部类cook
增加children接口,son类实现children接口功能
son类增加静态内部类play
增加接口pet,在主方法里使用匿名内部类实现pet接口

	public static void main(String[] args) {
		father Jack = new father();
		Jack.setName("Jack");
		Jack.setAge(30);
		Jack.show();
		
		mother m = new mother();
		m.setName("Jenny");
		m.setAge(27);
		m.show();
		m.assesscook();
		
			
		son s = new son();
		s.setName("Tom");
		s.setAge(7);
		s.show();
		s.school();
		s.like();
		
		son.play s1 = new son.play();
			
		String petname = "mimi";
		new pet() {
			public void eat() {
				System.out.println("eat");
			}
			public void shot() {
				System.out.println(petname+" miaomiao!");
			}
		}.shot();
		

		
	}

}

interface people{
	String familyname = "Black";
	
	void show();
}

class father implements people{
	
	public father() {
		super();
		
	}
	
	public father(String name, int age) {
		super();
		this.name = name;
		this.age = age;
	}

	private String name;
	private int age;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public int getAge() {
		return age;
	}
	public void setAge(int age) {
		this.age = age;
	}
	
	public void show() {
		System.out.println("My name is "+name+" "+familyname);
		System.out.println("I am "+age+" "+"olds");
	}
	
}

class mother extends father{
	public mother() {
		super();
		
	}

	public mother(String name, int age) {
		super(name, age);
		
	}

	private class cook{

		public cook() {
			super();
			System.out.println("Are you hungry?:)");
		}
		
	}
	public void assesscook() {
		cook c = new cook();
	}
}

interface children extends people{
	void school();
	
	void like();
}

class son extends mother
	implements children{
	
	public void school() {
		System.out.println("primary school");
	}
	
	public void like() {
		System.out.println("play computer games");
	}
	
	static class play{
		public play() {
			System.out.println("PS4,XBOX ONE,Nintendo switch");
		}
	}
}

interface pet{
	void eat();
	void shot();
}

运行结果`

My name is Jack Black
I am 30 olds
My name is Jenny Black
I am 27 olds
Are you hungry?:)
My name is Tom Black
I am 7 olds
primary school
play computer games
PS4,XBOX ONE,Nintendo switch
mimi miaomiao!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值