Write a Java program that illustrate Method Over-riding concept. Class Bond is extended by ConvertibleBond. Each of these classes defines a display() method that  outputs the string 'Bond" or "ConvertibleBond" respectively. Declare an array to hold six Bond objects. Initialize the elements of the array with a mix of Bond and  ConvertibleBond   objects. Execute a program loop to invoke the display() method of each object.

source file name: BondDemo.java

class Bond

{


public void display()

{

System.out.println("Bond object");

}


}

class ConvertibleBond extends Bond

{

public void display()

{

System.out.println("ConvertibleBond object");

}

}

class BondDemo

{

public static void main(String as[])

{

Bond bonds[]=new Bond[6];

bonds[0]=new Bond();

bonds[1]=new Bond();

bonds[2]=new ConvertibleBond();

bonds[3]=new ConvertibleBond(); 

bonds[4]=new Bond();

bonds[5]=new ConvertibleBond();


for(int i=0;i<bonds.length;i++)

bonds[i].display();


}

}

output:

D:\JavaPrograms\InheritancePrgs>javac BondDemo.java

D:\JavaPrograms\InheritancePrgs>java BondDemo
Bond object
Bond object
ConvertibleBond object
ConvertibleBond object
Bond object
ConvertibleBond object