Bifalgorithm post · Computer science one · Void Methods
How do you use methods defined in another Java class?
How do you use methods defined in another Java class? (Computer science one · Void Methods) — "Once a method has been defined in a class, you can make use of t…
Ideas in this flowchart
- Using a method defined in a class
- The class may need to be imported, depending on its location.
- The example class is Utils in the package unl.cse.
- Import Utils before the class declaration with import unl.cse.Utils;
- Invoke a method by referencing its class and using the dot operator.
- Examples of invoking methods from Utils
- Utils.sum(a, b) returns 30 when a is 10 and b is 20.
- Utils.getDistance(0.0, 0.0, 10.0, 20.0) uses literal values.
- Utils.getMonthlyPayment(p, r, 60) combines variables and a literal value.