Skip to Main Content

How can I import static members from another class?

User_LX1YUJan 31 2021

I'm trying to import static members from another class. The code examples below are in separate .java files. TestStaticClassMember is compiled first using:
javac TestStaticClassMember.java
followed by:
javac TestClass.java
TestStaticClassMember is not a recognised symbol to TestClass using the import construct:
import static TestStaticClassMembers.*;
featured within the examples below. Why is that?
public class TestStaticClassMember {
public static double getDate(double in)
{
return in;
}
}
import static TestStaticClassMember.*;
public class TestClass{
}
I've tried to recreate the compile error from the class RandomUtil.java (which has static members) and Branch.java that wants to use those static members from RandomUtil.
These classes are in the tree package from tree_animation found in the Oracle documentation.

Comments
Post Details
Added on Jan 31 2021
0 comments
21 views