June 2018
Beginner
722 pages
18h 47m
English
A variable of an interface type is declared using the corresponding interface name:
<Interface name> variableName;
It can be initialized by assigning to it null or an object (an instance) of the class that implemented the interface. Here is an example:
interface SomeInterface{ void someMethod();}interface SomeOtherInterface{ void someOtherMethod();}class SomeClass implements SomeInterface { void someMethod(){ ... }} class SomeOtherClass implements SomeOtherInterface{ void someOtherMethod(){ ... }}SomeInterface someInterface = new SomeClass();someInterface = new SomeOtherClass(); //not possible, errorsomeInterface.someMethod(); //works just finesomeInterface.someOtherMethod(); //not possible, error
We will talk more about assigning ...
Read now
Unlock full access