Skip to Main Content

Java SE (Java Platform, Standard Edition)

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

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
155 views