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();
}
}
2 Comments
Thanks for sharing such a great article, This is my first time on your blog and i am your fan now. keep it up..
ReplyDeleteWebsite Maker, Designer, Creator Near Me
E-commerce website development in india
Digital Marketing Company In India
Seo Company In Varanasi
Website design company in varanasi
cheap website design company bangalore
health and beauty products manufacturer
Bed net canopy manufacturer
Broken Hair Finishing Rod Manufacturer
Eyebrow Pencil Manufacturer
Health And Beauty Products Manufacturer
Thank you for your encouraging words.
DeletePost a Comment