Modifier keywords of interface interface

interface modifier

Can be modified with public, or use the default modifier (do not write modifier), but can not use private or protected modification

interface method

The default modifier is public abstract ; private or protected modifications cannot be used.
Remarks:
1.In JDK1.8, the interface can define static methods, which can be called directly by the interface name.

public interface Main{	
	static int ss() {
		return 0;
	}
}

2.In JDK1.8, the interface can use the default keyword to define non-abstract methods. When implementing the interface, you don't need to implement non-abstract methods. Of course, you can also choose to override.

public interface Main{	
	default int ss() {
		return 0;
	}
}

interface variable attributes

The default modifier is public static final ,

Guess you like

Origin blog.csdn.net/qq_47768542/article/details/109048189
Recommended