Results 1 to 1 of 1
Thread: How to use Static Imports
-
How to use Static Imports
Java Code:////////Fruits.java package MyConstants; public class Fruits { public static int apple = 500; public static int pear = 501; public static int orange = 502; public static int banana = 503; public static int strawberry = 504; } ////////////Colors.java package MyConstants; public class Colors { public static int white = 0; public static int black = 1; public static int red = 2; public static int blue = 3; public static int green = 4; public static int orange = 5; public static int grey = 6; } ///////////////////////StaticTest.java import static MyConstants.Colors.*; import static MyConstants.Fruits.*; public class StaticTest { public static void main(String args[]) { System.out.println("orange = " + orange); System.out.println("color orange = " + Colors.orange); System.out.println("Fruity orange = " + Fruits.orange); } }"The sole cause of man’s unhappiness is that he does not know how to stay quietly in his room." - Blaise Pascal
Similar Threads
-
Explicit static initialization with the static clause
By Java Tip in forum java.langReplies: 0Last Post: 04-16-2008, 11:07 PM -
Static imports (Java 5 and above)
By Java Tip in forum Java TipReplies: 0Last Post: 12-17-2007, 10:02 AM -
Organising Imports - Eclipse
By Java Tip in forum Java TipReplies: 0Last Post: 11-15-2007, 05:15 PM -
Error: Non-static method append(char) cannot be referenced from a static context
By paul in forum Advanced JavaReplies: 1Last Post: 08-07-2007, 05:05 AM -
Error: non-static variable height cannot be referenced from a static context at line
By fernando in forum AWT / SwingReplies: 1Last Post: 08-01-2007, 09:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks