In: Computer Science
1. define a class that has three different constructors.
2.
write code that overrides the following method
public double sqr(double num1) {
return num1*num1;
}
public class Num {
private double number;
// default constructor
Num() {
number = 0;
}
// parameterized constructor
Num(double i) {
number = i;
}
// copy constructor
Num(Num n) {
this.number = n.getNumber();
}
public double getNumber() {
return number;
}
public void setNumber(double aNumber) {
number = aNumber;
}
public double sqr(double num1) {
return num1 * num1;
}
public static void main(String[] args) {
Num n = new Num(5);
System.out.println(n.sqr(10));
}
}