kids2.java

来自「java 教程源码」· Java 代码 · 共 62 行

JAVA
62
字号
//c4:Kids2.java
//author:ZhangHongbin 
//This program is protected by copyright laws.
//each class has a main.  
class Mankind
{
	int sex;
	int salary;
	void manOrWoman( int sexValue)
	{ 
		switch(sexValue)
		{	
			case 0:
					System.out.println("a man");
					break;
			case 1:
					System.out.println("a woman");
					break;
			default:
					System.out.println("not a man or a women");
		}
	}
	void employed (int salaryValue)
	{
		if (salaryValue==0)
			System.out.println("no job ");
		else
 			System.out.println("job");
	}
	public static void main(String[] args) 
	{
		System.out.println("Mankind start----------");
		Mankind somePerson=new Mankind();//创建对象
		somePerson.sex=1;//给对象中的数据赋值
		somePerson.manOrWoman( somePerson.sex);//执行对象中的方法
		somePerson.salary=5; //给对象中的数据赋值
		somePerson.employed(somePerson.salary); //执行对象中的方法
	}

}
public class Kids2 extends Mankind
{
	int yearsOld;
	void printAge()
	{ 
		System.out.println("age= "+yearsOld);
	}
	void employed(int salaryValue)
	{
		System.out.println("kids should study and no work ");
	}
	public static void main(String[] args)
	{
		System.out.println("Kids2 start---------- ");
		Kids2 someKid=new Kids2();//创建对象
		someKid.sex=0;//给对象中的数据赋值
		someKid.manOrWoman( someKid.sex);//执行对象中的方法
		someKid.salary=5; //给对象中的数据赋值
		someKid.employed(100); //执行对象中的方法
	}
} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?