aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on Interfaces Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on Interfaces" Watch "Question on Interfaces" New topic
Author

Question on Interfaces

robl
Greenhorn

Joined: Aug 26, 2000
Posts: 25
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

Joined: Sep 24, 2000
Posts: 16
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

Joined: Mar 17, 2000
Posts: 5782
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).]


Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Question on Interfaces