多态 重要

public class qxy {

	public static void main(String[] args) {
       student s=new student();
       say(s);
       }
	public static void say(person p) {
	p.say();
    }
}
public interface  person {
	 int age=18;
    void say(); 
}
class student implements person {

	@Override
	public void say() {
		System.out.println("我是学生"+age);
		
	}
}

我是学生18

因为接口本身都是由全局常量和抽象方法组成 , 所以接口中的成员定义可以简写: 1、全局常量编写时, 可以省略public static final 关键字,例如: public static final String INFO = "内容" ; 简写后: String INFO = "内容" ; 2、抽象方法编写时, 可以省略 public abstract 关键字, 例如: public abstract void print() ; 简写后: void print()

Guess you like

Origin blog.csdn.net/weixin_43762083/article/details/119792510