The Java feature in Q1 which create a new version of predefined method getPerimeter() is called Polymorphism Override Overload Inheritance
OOPs
In today's technology-driven world, computer programming skills are in high demand. The object-oriented programming (OOP) approach is very much useful while designing and maintaining software programs. Object-oriented programming (OOP) is a basic programming paradigm that almost every developer has used at some stage in their career.
Constructor
The easiest way to think of a constructor in object-oriented programming (OOP) languages is:
1: create a class Pentagon, which implements the RegularPolygon interface. It should have a double field called length, as well as a constructor that initializes this length field to a given value.
2:
In the main() method of Pentagon class, add the following code:
RegularPolygon sq = new Square(10);
RegularPolygon penta = new Pentagon(20);
Write code to get the perimeter for sq and penta.
3:
In the main() method defined in Q2, add this line of code:
sq.getArea();
Will this code pass through compiler? What is the reason?
-
The Java feature in Q1 which create a new version of predefined method getPerimeter() is called
Polymorphism
Override
Overload
Inheritance
Trending now
This is a popular solution!
Step by step
Solved in 2 steps