package interface07;

//接口
public interface IStudent {
// 全局变量
void addStudent(int id, String name);

void deleteStudent(int id);
}

------------------------------

package interface07;

//实现接口要重写接口的方法
public class StudentMySql implements IStudent {

@Override
public void addStudent(int id, String name) {
System.out.println("这是mysql中添加学生的操作");
}

@Override
public void deleteStudent(int id) {
System.out.println("这是mysql中删除学生的操作");
}

}

------------------------------------

package interface07;

//实现接口要重写接口的方法
public class StudentOracle implements IStudent {

@Override
public void addStudent(int id, String name) {
System.out.println("这是oracle中的添加学生操作");
}

@Override
public void deleteStudent(int id) {
System.out.println("这是oracle中的删除学生操作");

}

}

-------------------------------

package interface07;

public class Test {

public static void main(String[] args) {

}

// 因为IStudent是接口,作为参数和变量,用参数变量调用作为参数的类中的方法
public static void handleStudent(IStudent stu) {
stu.addStudent(12, "s");
}

// 因为IStudent是接口,作为参数和变量,用参数变量调用作为参数的类中的方法
public static void handleStudentValue(IStudent a) {
a.deleteStudent(5);
}
}

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-04
  • 2022-01-12
猜你喜欢
  • 2021-07-03
  • 2022-12-23
  • 2021-07-13
  • 2022-12-23
  • 2021-09-06
  • 2022-12-23
  • 2021-12-05
相关资源
相似解决方案