python交易接口通达信,接口:对协定进行定义的引用类型。
使用
public class TestImp implements MyInterface{
@Override
public void impFunc1() {
System.out.println('python交易接口通达信,接口方法1');
}
}
python交易接口通达信,接口之间的多继承
python交易接口通达信,接口的常量
public interface MyInterface {
//可用的定义方式 [public] [static] [final] int a = 100;
public static final int a = 100;//其中的一写法
}
python交易接口通达信,接口的默认方法可以不覆盖重写,通过引用此python交易接口通达信,接口类的实例对象调用。python交易接口通达信,接口的默认方法可以解决python交易接口通达信,接口升级问题。
python交易接口通达信,接口的静态方法
继承父类并实现多个python交易接口通达信,接口
多个父python交易接口通达信,接口中的默认方法如果重复,子python交易接口通达信,接口需要带default关键字重写该默认方法
使用
python交易接口通达信,接口的私有方法
用于简化python交易接口通达信,接口默认方法中的重复代码
定义
public interface MyInterface {
default void impFunc1(){
System.out.println('python交易接口通达信,接口的默认方法1');
}
}
python交易接口通达信,接口私有默认方法
public interface MyInterface {
default void impFunc1(){
System.out.println('python交易接口通达信,接口的默认方法1');
print();
}
default void impFunc2(){
System.out.println('python交易接口通达信,接口的默认方法2');
print();
}
private void print(){
System.out.println('A');
System.out.println('B');
System.out.println('C');
}
}
一个类可以同时实现多个python交易接口通达信,接口
public class TestImp implements MyInterface1,MyInterface2 {
public void print(){
System.out.println('一个类可以同时实现多个python交易接口通达信,接口');
}
}
python交易接口通达信,接口中的错误写法
public interface MyInterface {
//python交易接口通达信,接口中不能使用静态代码块
static{
...
}
//python交易接口通达信,接口中不能使用构造方法
public MyInterface(){
...
}
}
如果实现类并没有覆盖重写python交易接口通达信,接口中的所有抽象方法,那么这个实现类自己必须是抽象类。
public abstract class TestImp implements MyInterface{
@Override
public void impFunc1() {
System.out.println('ok');
}
}
如果实现类实现的多个方法中存在重复的抽象方法,只需覆盖重写一次
public class TestImp implements MyInterface1,MyInterface2 {
@Override
public void impFunc() {
System.out.println('不同python交易接口通达信,接口中抽象方法重复,只需要覆盖重写一次');
}
}
python交易接口通达信,接口之间的多继承
public interface MyInterface extends MyInterface1,MyInterface2 {
abstract void impFunc();
}
public class TestImp implements MyInterface {
@Override
public void impFunc() {
System.out.println('MyInterface的方法');
}
@Override
public void impFunc1() {
System.out.println('MyInterface1的方法');
}
@Override
public void impFunc2() {
System.out.println('MyInterface2的方法');
}
}
python交易接口通达信,接口的默认方法
python交易接口通达信,接口私有静态方法
public interface MyInterface {
static void impFunc1(){
System.out.println('python交易接口通达信,接口的静态方法1');
print();
}
static void impFunc2(){
System.out.println('python交易接口通达信,接口的静态方法2');
print();
}
private static void print(){
System.out.println('A');
System.out.println('B');
System.out.println('C');
}
}
如果实现类实现的多个方法中存在重复的默认方法,需要覆盖重写一次
public interface MyInterface1 {
default void impFunc(){
System.out.println('MyInterface1中的默认方法');
};
}
public interface MyInterface2 {
default void impFunc(){
System.out.println('MyInterface2中的默认方法');
};
}
public class TestImp implements MyInterface1,MyInterface2 {
@Override
public void impFunc() {
System.out.println('不同python交易接口通达信,接口中抽象方法重复,只需要覆盖重写一次');
}
}
用于简化python交易接口通达信,接口静态方法中的重复代码
定义
public interface MyInterface {
static void impFunc1(){
System.out.println('python交易接口通达信,接口的静态方法1');
}
}
使用
public class Main {
public static void main(String[] args) {
TestImp t = new TestImp();
t.impFunc1();
}
}
python交易接口通达信,接口中的常量定义的同时必须赋值,且定义后不可改变。
定义
public interface MyInterface {
//可用的定义的方式 [public] [abstract] void impFunc1();
abstract void impFunc1();//其中一种写法
}
文章为作者独立观点,不代表观点