syntax for java interfaces
class ClassName [ extends SuperClassName ]
[ implements InterfaceName1 [, Interface Name2 �] ) {
class body
}
syntax for java interfaces
class ClassName [ extends SuperClassName ]
[ implements InterfaceName1 [, Interface Name2 �] ) {
class body
}
interface in java
the main idea of an interface is declaring functionality.
Suppose you program a game that has several types of characters.
These characters are able to move within a map. That is represented by Movable
interface
interface in java
interface Interface {
int INT_CONSTANT = 0; // it's a constant, the same as public static final int INT_FIELD = 0
void instanceMethod1();
void instanceMethod2();
static void staticMethod() {
System.out.println("Interface: static method");
}
default void defaultMethod() {
System.out.println("Interface: default method. It can be overridden");
}
private void privateMethod() {
System.out.println("Interface: private methods in interfaces are acceptable but should have a body");
}
}
Static, default, and private methods should have an implementation in the interface!
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us