This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
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).
 
Don't get me started about those stupid light bulbs.
 
subject: Question on Interfaces