Can u assign an instance of a class which implements an interface to an interface type?

This question is related to Oracle Interview

Showing Answers 1 - 1 of 1 Answers

David

  • Jan 16th, 2006
 

Definitely. That is actually the prefer way to make your client code more flexible and easier to maintain.For example, in a gaming program, you have:Breakable b = Factory.createObject();b.performBreak();It doesn't matter what concret Obejct Factory.createObect() returns, as long as it implements performBreak() method. The object return could be a character object, background object, automobile object.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions