实验六 接口的定义与使用

实验时间 2018-10-18

1、实验目的与要求

(1) 掌握接口定义方法;

(2) 掌握实现接口类的定义要求;

(3) 掌握实现了接口类的使用要求;

(4) 掌握程序回调设计模式;

(5) 掌握Comparator接口用法;

(6) 掌握对象浅层拷贝与深层拷贝方法;

(7) 掌握Lambda表达式语法;

(8) 了解内部类的用途及语法要求。

2、实验内容和步骤

实验1 导入第6章示例程序,测试程序并进行代码注释。

测试程序1:

l 编辑、编译、调试运行阅读教材214页-215页程序6-1、6-2,理解程序并分析程序运行结果;

l 在程序中相关代码处添加新知识的注释。

l 掌握接口的实现用法;

l 掌握内置接口Compareable的用法。

 

package interfaces;

import java.util.*;

/**
 * This program demonstrates the use of the Comparable interface.
 * @version 1.30 2004-02-27
 * @author Cay Horstmann
 */
public class EmployeeSortTest
{
   public static void main(String[] args)
   {
      Employee[] staff = new Employee[3];

      staff[0] = new Employee("Harry Hacker", 35000);
      staff[1] = new Employee("Carl Cracker", 75000);
      staff[2] = new Employee("Tony Tester", 38000);

      Arrays.sort(staff);

      //输出所有关于Employee对象的信息
      for (Employee e : staff)
         System.out.println("name=" + e.getName() + ",salary=" + e.getSalary());
   }
}
EmployeeSortTest

相关文章:

  • 2021-09-15
  • 2021-09-25
  • 2021-12-15
  • 2021-06-06
  • 2021-05-20
  • 2021-12-21
  • 2021-07-20
  • 2022-03-01
猜你喜欢
  • 2021-09-30
  • 2021-10-13
  • 2021-10-17
  • 2022-12-23
  • 2021-09-25
  • 2021-06-13
  • 2021-08-05
相关资源
相似解决方案