Working with Interfaces

Determine the output of the given code snippet.

interface Foo {
String name = "Foo";
void print();
} 

class Bar implements Foo {
String name = "Bar"; 

public void print() {
 System.out.println(name); // Line 1
}

public static void main(String[] args) {
Foo foo = new Bar(); // Line 2 
foo.print(); // Line 3
}
}
Options
  1. Foo
  2. Bar
  3. Compilation failure at Line 1
  4. Compilation failure at Line 2
  5. Compilation failure at Line 3

Related Posts

Close Bitnami banner
Bitnami