Question: Hey Java expert, go ahead and modify this code another way to take advantage of the dynamic binding in that code. Write the main method

Hey Java expert, go ahead and modify this code another way to take advantage of the dynamic binding in that code. Write the main method to demonstrate the correct functionality of the additions/modifications. INCLUDE SCREENSHOT OF modified WORKING CODE 


import java.util.Scanner;    //Defining the abstract class that will overide to calculate both areas  abstract class Base   {      //Setting varibales for the arae, length, and height      double l, h, area;            void setDimentions()       {          double length, height;          System.out.println("Enter the length: ");          Scanner s = new Scanner(System.in);          length = s.nextDouble();          System.out.println("Enter the height: ");          height = s.nextDouble();          this.l = length;          this.h = height;      }            abstract void computeArea();   }    //this overrides the computeArea() method so that it can also be used to calculate the area of triangle  class Triangle extends Base   {      void computeArea()       {          area = (l * h) / 2;          System.out.println("The area of a triangle is = " + this.area);      }  }    //this overrides the computeArea() method so that it can also be used to calculate the area of rectangle  class Rectangle extends Base   {      void computeArea()       {          area = (l * h);          System.out.println("The area of a rectangle is = " + this.area);      }  }    //Uses computeArea() to calculate the two different areas by overriding the methos defined in the Base class  public class Calculator   {      public static void main(String[] args)       {          Triangle t = new Triangle();          Rectangle r = new Rectangle();          System.out.println("Find the area of a triangle");          t.setDimentions();            t.computeArea();            System.out.println("Find the area of rectangle");          r.setDimentions();            r.computeArea();      }  }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Operating System Questions!