Explain why and give examples In OO programming Polymorphism

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

Solution

Polymorphism, generally depicts \"many forms,\" that it has the capability for the object which belongs to the subclass of any other base class as well as it also act as an object of the base class. so we can consider the parent class is, having so many forms.

example:

class vhc implements abc
{
   private String str;
   vhc (String str)
   {
      this.str = str;
   }
   String getstr ()
   {
      return str;
   }
   public void first ()
   {
   }
   public void end ()
   {
   }
}
class bus extends vhc
{
   bus (String str)
   {
      super (str);
   }
   public void first ()
   {
      System.out.println (\"start the bus.\");
   }
   public void end ()
   {
      System.out.println (\"stop the bus.\");
   }
   public String toString ()
   {
      return getstr ();
   }
}
class abc
{
   public static void main (String [] args)
   {
      bus c = new bus (\"...\");
      c.first ();
      c.end ();
      System.out.println (c.toString ());
      StartStop ss = c;
      ss.first ();
      ss.end ();
      System.out.println (ss.toString ());
   }
}

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

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site