Based on the particle example redo the areashapes assignment toimplement the polymorphism concept (via method overloading andoverriding) whereby the user selects a shape, and the programcalculates, and displays the shape's area using \"displayArea()\".
/*
* To change this license header, choose License Headers in ProjectProperties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package areashapes;
/**
*
* @author Maore
*/
public class AreaShapes{
public static void main(String[] args) {
Circle c=new Circle();
Triangle t= new Triangle();
Trapezium tz= new Trapezium();
Oval o= new Oval();
System.out.println(\"Area of the Circle:\"+c.area());//singleinheritance
System.out.println(\"Area of the Triangle is:\" + t.area());
System.out.println(\"Area of the Trapezium is:\" + tz.area());
System.out.println(\"Area of the Oval is:\" + o.area());
MethodsRectangle mr=new MethodsRectangle();//methodoverloading
 Â
//the data type is integer therefore displayArea method will beinvoked.
System.out.println(\"Area of the Rectangle:\"+mr.displayArea(3,4));
//double data type therefore double type method will beinvoked
System.out.println(\"Area of the Rectangle:\"+mr.displayArea(3.4,4.3));
 Â
 Â
//method overriding
Dimensions d=new MethodsRectangle();
d.displayArea();//this will get the method displayArea from theMethodsRectangle class not from the Dimensions class because it isoverridden by the
//child class
 Â
 Â
//final keyword
final double unchangeble=1;
 Â
System.out.print(unchangeble);
 Â
}
}
class Dimensions{ //parent or base class
double radius=7;
double pi= 8;//circle
double length,width;//rectangle
double base,height;//triangle
double a=14,b=16,h=19;//trapezium;
double a1,b1;//oval;
 Â
//method override
public void displayArea() {
System.out.print(\"Display Area\");
}
 Â
}
//single inheritance
class Circle extends Dimensions{
 Â
public double area() {
return (super.pi*super.radius*super.radius);
// super keyword to get the variables of the previous class
}
}
//hierarchical inheritance i.e.,all every class in the programinheriting the parent class
// Circle class included in this hierarchical inheritance)
class Triangle extends Dimensions{
double base=7;
double height= 8;
 Â
 Â
public double area() {
return(this.base*this.height);//here we've used this keyword foraccess the variable of current class
}
}
class Trapezium extends Dimensions{
 Â
public double area() {
return((super.a+super.height)/2)*super.h;//super keyword to accessthe variable of current class
}
}
 Â
 Â
 Â
class Oval extends Dimensions{
double a1= 16;
double b1=20;
double pi= 3.14;
public double area() {
return((this.a1*this.b1*this.pi)/2);//this keyword to access thevariable of current class
}
}
//and finally we will look into the method overloading and methodoverriding in this class
class MethodsRectangle extends Dimensions{
public int displayArea(int x,int y) {// this method gives area forinteger dimensions
return(x*y);
}
public double displayArea(double x,double y) {
return(x*y);//this method will give area for double typedimensions
}
public void displayArea() {
System.out.print(\"\nparent class method overriden by this classmethod !!! \");//this method will override the method in Dimensionsclass
}
 Â
}
 Â
 Â