Instantiate an interface
Posted: Sun Sep 27, 2015 11:11 am
I hope it's okay that I post this question in the General Java Discussion...
Theoretically speaking, interfaces cannot be instantiated, except if you override all of the interface's abstract methods like so:
public static void main(String[] args) {
List al = new List() {
@Override
public int size() {
}
@Override
public boolean isEmpty() {
}
@Override
public boolean contains(Object o) {
}
etc...
Theoretically, we cannot instantiate an interface, but in practice you actually can. If the exam asks a question like An interface cannot be instantiated. Should we then answer true or false?
Theoretically speaking, interfaces cannot be instantiated, except if you override all of the interface's abstract methods like so:
public static void main(String[] args) {
List al = new List() {
@Override
public int size() {
}
@Override
public boolean isEmpty() {
}
@Override
public boolean contains(Object o) {
}
etc...
Theoretically, we cannot instantiate an interface, but in practice you actually can. If the exam asks a question like An interface cannot be instantiated. Should we then answer true or false?