Write the declaration for class B. The class’s members should be as follows:
m, an integer. This variable should not be accessible to code outside the class or to any class that extends class B.
n, an integer. This variable should be accessible only to classes that extend class B or in the same package as class B.
setM, getM, setN, and getN. These are the mutator and accessor methods for the member variables m and n. These methods should be accessible to code outside the class.
calc. This is a public abstract method.
Next, write the declaration for class D, which extends class B. The class’s members should be as follows:
q, a double. This variable should not be accessible to code outside the class.
r, a double. This variable should be accessible to any class that extends class D or in the same package.
setQ, getQ, setR, and getR. These are the mutator and accessor methods for the member variables q and r. These methods should be accessible to code outside the class.
calc, a public method that overrides the superclass’s abstract calc method. This method should return the value of q times r.
Here is my code the stared ones is the part I got wrong –
import java.io.*;
public class ClassB{
***private int m;
public int n;***
public setM(int minteger){
m=minteger;
}
public void getM(){
return minteger;
}
public setN(int ninteger){
n=ninteger;
}
***public void getN(){
return ninteger
}***
}
public class ClassD extends ClassB
{
private double q;
***public double r;***
public setQ(double qdouble){
q=qdouble;
}
public void getQ(){
return qdouble;
}
public setR(double rdouble){
r=rdouble;
}
public void getR(){
return rdouble
}
}
***public abstract class calc{
return r*q
}***
make
int nanddouble rasprotected.
In
getN()you should writereturn n;Similarly ingetM()writereturn m;,getQ()writereturn q;and ingetR()writereturn r;You abstract class should look like:
You didn’t clearly mention where to use/override
calcmethod