Embed presentation
Downloaded 28 times

![class annual extends wallet
{
annual(double a, double b)
{
super(a,b);
}
double salary()
{
System.out.print("n Annual income is = ");
return dim1*dim2;
}
}
class salary
{
public static void main(String arr[])
{
wallet d = new wallet(10,10);
monthly m = new monthly(330,30);
annual a = new annual(10000,12);
walletuv;
uv = m;
System.out.print(+uv.salary());
uv = a;
System.out.print(+uv.salary());
uv = d;
System.out.print(+uv.salary()+"n");
}
}](https://image.slidesharecdn.com/methodoverriding-131127075407-phpapp01/85/Method-overriding-in-java-2-320.jpg)


This Java program demonstrates method overriding. It defines a wallet class with dimensions and a salary method that returns 0. Monthly and annual classes extend wallet, overriding the salary method to return the product of the dimensions, and printing the appropriate salary text. The main method creates instances of each class, assigns them to a wallet reference variable, and calls salary to print the results.

![class annual extends wallet
{
annual(double a, double b)
{
super(a,b);
}
double salary()
{
System.out.print("n Annual income is = ");
return dim1*dim2;
}
}
class salary
{
public static void main(String arr[])
{
wallet d = new wallet(10,10);
monthly m = new monthly(330,30);
annual a = new annual(10000,12);
walletuv;
uv = m;
System.out.print(+uv.salary());
uv = a;
System.out.print(+uv.salary());
uv = d;
System.out.print(+uv.salary()+"n");
}
}](https://image.slidesharecdn.com/methodoverriding-131127075407-phpapp01/85/Method-overriding-in-java-2-320.jpg)
