[Solved] How do] I call one method from a class to another class? [closed]


It Should be something like that:

public class MyClass
{
    public void setSerial(int ser)
    {
        serialNumber = ser;
    }

    public double computeArea()
    {
        return width*length;
    }
}

But that won’t work:

public void displayBoxes(){
    MyClass myClass = new MyClass();
    DecimalFormat df = new DecimalFormat("0.000");
    System.out.println(toString());
    System.out.println("The rectangle with the serial number " + myClass.setSerial(12345) + " has the largest area: " + myClass.ComputerArea());

Because:
a. The setSerial() method is void. Doesn’t return anything.
b. The ComputerArea() method doesn’t take any arguments so there’s no knowledge of what is width and what is length in the computerArea() method….

solved How do] I call one method from a class to another class? [closed]