Bifalgorithm post · Computer science one · Using Methods
How do you use methods defined in another Java class?
How do you use methods defined in another Java class? (Computer science one · Using Methods) — "Once a method has been defined in a class, you can make use of…
Ideas in this flowchart
- Using methods defined in a class
- The class may need to be imported depending on its location
- Import the class before the class declaration
- The example class Utils is in the package unl.cse
- After importing the class, invoke one of its methods
- Reference the class that contains the method
- Use the dot operator to access the method
- Examples of invoking Utils methods
- Utils.sum(a, b) returns the sum of a and b
- Utils.getDistance(0.0, 0.0, 10.0, 20.0) uses literal values
- Utils.getMonthlyPayment(p, r, 60) uses variables and a literal value