Java——5

public class Person {
	
public String name;//姓名
public int age;//年龄
public String birthday;//出生日期
//
//
//public Person{
//	
//}

public  Person (String name,int age,String birthday){
	this.name=name;
	this.age=age;
	this.birthday=birthday;
	
}

/**
 * 获得对象的信息*/
public String getInfo(){
return "姓名:" + name + "\n年龄:" + age 
	+ "\n出生日期:" + birthday;
}
}

2

public class Student extends Person{

public String school ;//学校名字
public Student(String name,int age,String birthday,String school){
	super(name,age,birthday);
	this.school=school;
}

public String getInfo(){
return "姓名:" + name + "\n年龄:" 
+ age + "\n出生日期:" + birthday + "\n学校为:"+school;
}
}

/*111
public class Student {  
private String name;  
private int age;  
private String birthday;  
private String school;  

public Student(String name, int age, String birthday, String school) {  
    this.name = name;  
    this.age = age;  
    this.birthday = birthday;  
    this.school = school;  
}  
public String getInfo() {  
    return "Name: " + name + ", Age: " + age + ", Birthday: " + birthday + ", School: " + school;  
}  
}  */

3


public class Test {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		//实例化一个叫center的对象
		
				School center=new School();
				//初始化center对象
				center.school="重庆中心";
				center.classNum=10;
				center.labNum=20;
				//调用center对象的方法
				System.out.println(center.getMessage());
	}

}

4

public class TestDemo { 
	public static void main(String[] a){
	
		Student student1 = new Student("鱼",12,"2020-06-11","cqcet");
		System.out.println(student1.getInfo());
}
}


/*222
public class TestDemo {  
public static void main(String[] args) {  
    Student student = new Student("鱼", 12, "2001-9-8", "cqcet");  
    System.out.println(student.getInfo());  
}  
}*/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值