Java
Java
Create a class
Circle.java in a package “com.cognizant.shapes” , add a float instance variable
radius and add a default constructor (Constructor 1) for the class. This
constructor should initialize the radius to a default value
1.5f.
The above constructor should be invoked from a main method from another class,
Shape.java (in different package com.cognizant. geometry).
Problem Statement 2:
Overloading constructors and using “this” keyword.
In the Circle.java class created above add an instance float variable
pi and create two overloaded constructors.
NOTE:
The instance variable and the method argument should be named same as “radius”.
The constructor “constructor 2” should be invoked from a main method from class,
Area.java (in a package com.cognizant.shapes).
Problem Statement 4:
Applying access specifiers to constructors/variables
(Other classes must not be able to call this constructor). Also restrict the access
to the variable radius to class levelProvide package level access to Constructor 2
(Classes in other package must
not be able to access this constructor). Also provide package level access to the
variable pi.
Problem Statement 5:
Create two methods and calculate area and circumference of a Circle
In the
Circle.java class, create two methods as listed below