java类扩展案例

java类扩展案例

class Person2{
	public String name;
	public Person2(String name){
		this.name=name;
	}
	public void eat() {
		System.out.println(name+"吃饭了");
	}
}


class PersonExtension{
	public static void run(Person2 p,String sport) {
		System.out.println(p.name+"开始运动:"+sport);
	}
}
public class ClassExceptionDemo {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Person2 p=new Person2("Fjy");
		p.eat();
		PersonExtension.run(p, "打篮球");
	}

}

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_43299461/article/details/86551321