Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on Interfaces

 
robl
Greenhorn
Posts: 25
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which of the following statements are true?
1) An interface can only contain method and not variables
2) Java does not allow the creation of a reference to an interface with the new keyword.
3) A class may extend only one other class and implement only one interface
4) Interfaces are the Java approach to addressing the single inheritance model, but require implementing classes to create the functionality of the Interfaces.
The answer did not include number 2, but I thought that an interface could not be instantiated.
Please explain why the new keyword can be used with an interface.

 
Shankar G
Greenhorn
Posts: 16
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree -- as per JLS "Every interface is implicitly abstract", which means it cannot be instantiated with the new keyword. Refer to the section http://java.sun.com/docs/books/jls/html/9.doc.html#30820 of JLS.
Any comments?
- Shankar.
Originally posted by robl:
Which of the following statements are true?
1) An interface can only contain method and not variables
2) Java does not allow the creation of a reference to an interface with the new keyword.
3) A class may extend only one other class and implement only one interface
4) Interfaces are the Java approach to addressing the single inheritance model, but require implementing classes to create the functionality of the Interfaces.
The answer did not include number 2, but I thought that an interface could not be instantiated.
Please explain why the new keyword can be used with an interface.


 
Ajith Kallambella
Sheriff
Posts: 5782
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
May be because you can instantiate an anonymous class that implements an interface using the new keyword. You can also assign the reference to such an object to an interface type.

Perhaps Marcus( Marcus, are you listening?? ) thinks this is the scenario covered by option #2, and hence it is right.

Ajith
[This message has been edited by Ajith Kallambella (edited August 28, 2000).]
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic