编程语言
首页 > 编程语言> > JAVA---继承性

JAVA---继承性

作者:互联网

package exer;

public class ExtendsTest {
	public static void main(String[] args) {
		Person p=new Person();
		Student s=new Student();
		s.name="哈哈";
		System.out.println(s.name);
		
	}
}
class Person{
	String name;
	
	Person(){
		
	}
	Person(String name){
		this.name=name;
	}
	public void eat(){
		System.out.println("吃");
	}
}
class Student extends Person{
	String score;
	Student(){
		
	}
	public void study(){
		System.out.println("学习");
	}
}

标签:JAVA,name,子类,---,Person,继承性,父类,public,String
来源: https://www.cnblogs.com/fate-/p/15810688.html