Results 1 to 4 of 4
Thread: constant variables questions
- 05-06-2011, 04:51 AM #1
Member
- Join Date
- Apr 2011
- Posts
- 48
- Rep Power
- 0
- 05-06-2011, 05:12 AM #2
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You can declare it in a class as public static final short = final. Some other things you can think of is the PI constant supplied by the class Math.
It is declared as
If you add that short to a class you can import the package and use it asJava Code:public static final double PI = 3.141592....
Java Code:ClassName.CONTANT_NAME
- 05-06-2011, 05:30 AM #3
Member
- Join Date
- Apr 2011
- Posts
- 48
- Rep Power
- 0
how to import?
- 05-06-2011, 05:34 AM #4
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
You have to package your class with the constant first, than import the class.
Using Package Members (The Java™ Tutorials > Learning the Java Language > Packages)
Creating and Using Packages (The Java™ Tutorials > Learning the Java Language > Packages)
Basically, you create a class and make the first line
As an example, I have written a class which is in the texteditor/actions directory, and the first line of all the files in this folder isJava Code:package directoryName
Then I have some other classes which rely on the classes in the directory texteditor/actions. I gain access to them in other files with this lineJava Code:package texteditor.actions
You will have to package a class with the constants and then import it when necessary.Java Code:import texteditor.actions.*;
Similar Threads
-
Problem accessing a constant defined in another class
By subith86 in forum New To JavaReplies: 6Last Post: 01-26-2011, 07:49 PM -
How to use the split method with a non-constant delimiter
By Unnel in forum Advanced JavaReplies: 3Last Post: 01-03-2011, 03:48 PM -
switch() don't work with constant
By jarek in forum Advanced JavaReplies: 3Last Post: 11-19-2010, 08:59 AM -
static constant and performance
By felixtfelix in forum New To JavaReplies: 2Last Post: 08-31-2010, 01:43 PM -
Constant size for JTextArea
By itaipee in forum AWT / SwingReplies: 1Last Post: 12-30-2008, 04:12 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks