Java inheritance

 1. Java and Multiple inheritance java doesn't supported multiple inheritance. These means that a class can't extends more than one class therefore following statement illegal.

           Public class extends animal,mommal                {

           However a class can implement one or more interface, which has helped java separate of the impossibility of multiple inheritance. The extends keyword is used once and the parent interface are declared in a separate list for example if the hockey interface extended board sports and event it to be declared as-

             Public interface hockey extends sports, event.

Following example demonstrates the above explanation

Inheritance Event { public void start ();}

Inheritance Sports { public void Play ();}

Inheritance Hockey extends Sports, Event { public void Show ();}

Public class test { public static void main (string ARGS[])

{ Hockey H¹=new Hockey ();

{

  Public void start ()

{

  System.out.println("start event");

}

  Public void Play ()

{

  System.out.println("play sports");

}

  Public void Show ()

{

  System.out.println("show hockey");

}

};

H¹.Start();

H¹.Play();

H¹.Show();

}

}


 \\✍️ Pinku khan- Software Engineer\\



Comments