码迷,mamicode.com
首页 > 编程语言 > 详细

Java面向对象练习题继承之人种

时间:2016-05-22 23:19:36      阅读:411      评论:0      收藏:0      [点我收藏+]

标签:

技术分享

 

//People类

package 继承;

public class People {
	
	private String name;
	private double height;
	private double weight;
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public double getHeight() {
		return height;
	}
	public void setHeight(double height) {
		this.height = height;
	}
	public double getWeight() {
		return weight;
	}
	public void setWeight(double weight) {
		this.weight = weight;
	}
	
	public void speakHello()
	{
		System.out.println("Hello");
	}

}

  

 

//Chinapeople类

package 继承;


//继承
//Object 是所有类的父类
public class Chinapeople extends People {

	public void Chinesekongfu()
	{
		System.out.println("坐如钟,站如松");
	}
	
	//重写 也叫覆盖
	public void speakHello()
	{
		System.out.println("你好");
	}
}

  

//Americanpeople类

package 继承;

public class Americanpeople extends People {
	
	public void americanBoxing()
	{
		System.out.println("直拳,勾拳");
	}
}

  

 

//Testpeople类

package 继承;

public class Textpeople {

	public static void main(String[] args) {
		
		People p=new People();
		p.speakHello();
		
		System.out.println("中国人:");
		Chinapeople cp=new Chinapeople();
		cp.speakHello();
		cp.Chinesekongfu();
		
		System.out.println("美国人:");
		Americanpeople ap=new Americanpeople();
		ap.speakHello();
		ap.americanBoxing();
	}

}

  

 

运行结果

技术分享

Java面向对象练习题继承之人种

标签:

原文地址:http://www.cnblogs.com/mutougezi/p/5518142.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!