实现接口的类 public class Stu1 implements Student info∥实现学生情况接口 String name; int birth year ∥类自己的成员变量 public Stul(String n1, int y) name = n1 birth year=y public int ageo ∥实现接口的方法 return year-birth year; public void output ∥实现接口的方法 System. out println(this name +" this age 0+3") public static void main(String args Stu1s1= new stu1("李明",1980); s1output (:
实现接口的类 public class Stu1 implements Student_info //实现学生情况接口 { String name; int birth_year; //类自己的成员变量 public Stu1(String n1,int y) { name = n1; birth_year = y; } public int age() //实现接口的方法 { return year - birth_year; } public void output() //实现接口的方法 { System.out.println(this.name +" "+ this.age()+"岁"); } public static void main (String args[]) { Stu1 s1 = new Stu1("李明",1980); s1.output(); } }
个类实现多个接口 interface Student scour∥学生成绩接口 float total void output public class Stu2 implements Student info, Student scour ∥实现学生情况接口、学生成绩接口 String name int birth year; float math, english, computer public Stu2 (String n1, int y, float a, float b, float c) name =n1 birth year =y math= a english b computer=
一个类实现多个接口 interface Student_scoure //学生成绩接口 { float total(); void output(); } public class Stu2 implements Student_info, Student_scoure { //实现学生情况接口、学生成绩接口 String name; int birth_year; float math,english,computer; public Stu2(String n1,int y,float a,float b,float c) { name = n1; birth_year = y; math = a; english = b; computer = c; }