Java问题:编写一个java程序,名为InterfaceDemo.java,运行结果为:
- 提问者网友:末路
- 2021-04-20 03:40
学生类使用Person接口中的年龄成员变量:66
学生类的姓名是:学生
学生类的年龄是:22
- 五星知识达人网友:掌灯师
- 2021-04-20 04:45
package year2009.m12.d12;
public interface Person {
public final String NAME = "人";
public final int AGE = 66;
public abstract void display();
}
-------------------------------------------------------------
package year2009.m12.d12;
public class Student implements Person {
private String sName;
private int sAge;
public Student(String sName,int sAge) {
this.sName = sName;
this.sAge = sAge;
}
@Override
public void display() {
System.out.println("学生类使用Person接口中姓名成员变量:" + NAME);
System.out.println("学生类使用Person接口中的年龄成员变量:" + AGE);
System.out.println("学生类的姓名是:" + sName);
System.out.println("学生类的年龄是:" + sAge);
}
}
-----------------------------------------------------------------
package year2009.m12.d12;
public class InterfaceDemo {
public static void main(String[] args) {
Student s = new Student("学生",22);
s.display();
}
}