L
Linus Flustillbe
Does a method have to be part of a class that gets instatiated or can it
live in a class to be available to all other classes without
instantiation...it's available when it's imported?
I created a package called helperClasses and a class like this
package helperClasses;
public class rType {
public boolean isBetweenInt(int a, int b, int c)
{
return (a <= c && a >=b);
}
public boolean isBetweenDouble(double target, double lower, double upper)
{
return (target <= upper && target >= lower);
}
}
Is there a way to make the methods contained in rType avaiable by simply
importing the class or does it have to be instantiated? I'd like to be
able to, in a Java program, execute the following lines
import helperClasses;
public class test {
public static void main(String[] args) {
boolean isBetween = inBetweenInt(4,6,87);
System.out.println(isBetween);
}
}
In this case, it would say "false"
Here is my working tester
import helperClasses;
class rTypeTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
rType myTest = new rType();
boolean hello = myTest.isBetweenInt(4,6,87);
System.out.println(hello);
}
}
And actual output
false
Just seems like extra work and..even worse... if you create an instance
of rType and it has 250 methods, isn't that gonna potentially slow
things down.
So basically what I want to do is create a whole bunch of methods, put
them in one class and have them all available on demand just by
importing the class...no instantiations required.
Make sense? This is probably silly so if it is, just ignore me..I'll
go away
live in a class to be available to all other classes without
instantiation...it's available when it's imported?
I created a package called helperClasses and a class like this
package helperClasses;
public class rType {
public boolean isBetweenInt(int a, int b, int c)
{
return (a <= c && a >=b);
}
public boolean isBetweenDouble(double target, double lower, double upper)
{
return (target <= upper && target >= lower);
}
}
Is there a way to make the methods contained in rType avaiable by simply
importing the class or does it have to be instantiated? I'd like to be
able to, in a Java program, execute the following lines
import helperClasses;
public class test {
public static void main(String[] args) {
boolean isBetween = inBetweenInt(4,6,87);
System.out.println(isBetween);
}
}
In this case, it would say "false"
Here is my working tester
import helperClasses;
class rTypeTest {
public static void main(String[] args) {
// TODO Auto-generated method stub
rType myTest = new rType();
boolean hello = myTest.isBetweenInt(4,6,87);
System.out.println(hello);
}
}
And actual output
false
Just seems like extra work and..even worse... if you create an instance
of rType and it has 250 methods, isn't that gonna potentially slow
things down.
So basically what I want to do is create a whole bunch of methods, put
them in one class and have them all available on demand just by
importing the class...no instantiations required.
Make sense? This is probably silly so if it is, just ignore me..I'll
go away