Re: Question regarding methods and classes
Linus Flustillbe wrote:
So that works really well.
package helperClasses;
By widespread but not quite universal convention, package names should be all lower case.
public class rType {
By universal convention, class names should begin with an upper-case letter.
<http://www.oracle.com/technetwork/java/codeconv-138413.html>
public static boolean isBetween(int a, int b, int c)
{
return (a <= c && a >=b);
PLEASE DO NOT INDENT USENET CODE POSTS WITH TABS!
}
public static boolean isBetween(double target, double lower, double upper)
Why did you switch to intelligent variable names here, but not in the other method?
{
return (target <= upper && target >= lower);
PLEASE DO NOT INDENT USENET CODE POSTS WITH TABS!
}
}
import static helperClasses.rType.*;
class rTypeTest {
By universal convention, class names should start with an upper-case letter.
public static void main(String[] args) {
boolean hello = isBetween(4,6,87);
System.out.println(hello);
boolean hello2 = isBetween(5.4, 2.3, 9.2);
System.out.println(hello2);
}
}
false
true
I understand the concept of overloading methods... I haven't done much
Java in few years so I'm taking a refresher by going through the Java
Tutorial. What does adding the "static" modifier to the import
statement do? Since the methods in the rType class are already defined
Read the manual.
GIYF.
<http://lmgtfy.com/?q=Java+import+static>
as being static (only one instance no matter how many times the class is
instantiated ... see I read up on that) why do we need the modifier
except to make the code compile? Or is that the only reason.. because
Java needs it?
The "import static" directive lets you import static (get it?) members from another class. This obviates having to prefix those members with the class and the dot operator.
--
Lew