Challenge 2: Implement and Override the Method

Can you override the getArea() method in a derived class of the base class? A solution is placed in the "solution" section to help you, but we would suggest you try to solve it on your own first.

Problem Statement #

Write a method in a Circle class which overrides a method in a Shape class i.e. getArea() and returns the area of a circle.

The value of Pi is 3.14.

You are given a partially completed code in the editor. Modify the code so that the code prints the following:

Input: #

radius

Output: #

area of a circle

Sample Input #

       Shape circle = new Circle(2);
       System.out.println(circle.getArea());

Sample Output #

                  12.56

Get hands-on with 1200+ tech skills courses.