Equal symbol
equal symbol
Within most programming languages the symbol used for assignment is the equal symbol.
<span>Beside homework, what products can you use for personal use? Identify three uses and briefly describe.
</span>
Answer:
All are True
Explanation:
a. A constructor must have the same name as that of a class. For example
public class MyFirstClass{ // this is the class name
public MyFirstClass() } // the constructor having the same name as class.
b. Constructors never have a return type not even void because it is only used to initialize the values of data members of the class when the object of the class is created so constructors are not directly called hence they do not need to have a return type.
c. Constructors are invoked using the new operator.
When the new object is created the constructor is invoked in order to initialize the variables of a class. The memory is allocated to the object and then the constructive is invoked for the purpose to initialize the object.
Answer:
import java.lang.Object
import java.lang.Math
public class RegularPolygon extends java.lang.Object{
public void randomize(RegularPolygon c){
int min = 10, max1 = 20;
double min1 = 5, max1 = 12;
double range = (max - min) + 1;
double range1 = (max1 -min1) + 1
int side = (Math.random() * range) + min;
double len = (Math.random() * range1) + min1;
c.setNumSides(side);
c.setSideLength( len);
}
public static void main(String[] args) {
RegularPolygon r = new RegularPloygon();
randomize(r);
}
}
Explanation:
The randomize method accepts a regular polygon class as its only parameter and assigns a random number of sides and the length of these sides with the 'Math.random' function.