आप शून्य हो जाएंगे क्योंकि टिप्पणी में रॉबर्ट किलर द्वारा सही तरीके से इंगित किया गया है।
आप क्लास नाम का उपयोग कर स्थिर चर का संदर्भ लें।
उदाहरण ClassName.variablename। आपके मामले में
main.inString
अपनी मुख्य कक्षा चलाएं। जब आप इन स्ट्रिंग को चलाते हैं तो कक्षा के निर्माता में प्रारंभ किया जाता है। अब आप नीचे के रूप में Myclass में इसका उल्लेख कर सकते हैं।
public class main {
public static StringBuffer inString;
public main()
{
inString = new StringBuffer("Our aim is to make a 15 realistic game, where grinding powerlines and doing a tailwhip isn't easy, like in the real world. A game in which you will feel like you're actual riding. A game in which creativity and beauty are combined. ");
inString = new StringBuffer(inString.toString().replaceAll(" +", " "));
new MyClass();
}
public static void main(String[] args) {
new main();
}
}
अब MyClass में स्थिर चर का संदर्भ लें।
class MyClass {
public MyClass() {
System.out.println("............."+main.inString);// refer to static variable
}
}
आप कक्षा के निर्माता को चर भी पारित कर सकते हैं।
public class main {
public StringBuffer inString;
public main()
{
inString = new StringBuffer("Our aim is to make a 15 realistic game, where grinding powerlines and doing a tailwhip isn't easy, like in the real world. A game in which you will feel like you're actual riding. A game in which creativity and beauty are combined. ");
inString = new StringBuffer(inString.toString().replaceAll(" +", " "));
new MyClass(inString);
}
public static void main(String[] args) {
new main();
}
}
फिर MyClass में
public class MyClass
{
public MyClass(StringBuffer value)
{
System.out.println("............."+value);
}
}
लिंक @Why are static variables considered evil?
क्योंकि आपने इसे अन्य स्थैतिक शून्य मुख्य में शुरू नहीं किया है, इसलिए आप वहां चल रहे हैं – Yoda