Explain why and give examples In OO programming Polymorphis

. Explain why and give examples.   “In OO programming Polymorphism is only possible when using Interface or Inheritance” . (5 points)


Q2. Can we create an object of type Interface? Explain your answer. (5 points)

Solution

Q2).

Answer :

      We can\'t Create an Object of type Interface Because interface contains only abstract methods.Abstract Methods do not have a body of Implementation Code.But it is possible to cteate Interface Object with inner classes and anonymous Objects.

                   Interface is a collection of only Methods with no body(i.e.Abstract) and there is no constructor you can\'t create Object.Consider the example of listener interface it has method onClick now suppose i am creating of interface then it won\'t have definition of onClick method how would it know that what to do when onClick method is called now suppose i want that no,i would define method in interface(i know not possible)then every class implementing that interface will have the same things to do whenever onClick Method is called.so it Clear that we can\'t create object of type Interface..

......................................................................

. Explain why and give examples. “In OO programming Polymorphism is only possible when using Interface or Inheritance” . (5 points) Q2. Can we create an object

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site