Examples of Variants
Let's take a look at a few more instances of variants in action!
We'll cover the following
The shape
Variant
We’ll create a shape
variant which contains the Square
, Circle
, and Triangle
constructors. Each constructor will have arguments of the float
type as its dimensions.
Whenever one of the constructors is called, the area for that shape will be calculated through the getArea()
method.
Implementation
Create a free account to view this lesson.
By signing up, you agree to Educative's Terms of Service and Privacy Policy