Java: how to have global values inside a class?

Posted by HH on Stack Overflow See other posts from Stack Overflow or by HH
Published on 2010-04-09T11:59:48Z Indexed on 2010/04/09 12:13 UTC
Read the original article Hit count: 241

Filed under:
|
|

I want less methods. I want a common global TestClass from which I could use any of its value inside the class.

import java.util.*;
import java.io.*;

public class TestClass {
        TestClass(String hello){
                String hallo = hello;
                String halloSecond = "Saluto!";
        }
        public static void main(String[] args) {
                TestClass test = new TestClass("Tjena!");
                System.out.println("I want "Tjena!": " + test.hallo);
                TestClass testSecond = new TestClass("1");
                System.out.println("I want Saluto!:" + test.halloSecond);
                System.out.println("I want Saluto!:" + testSecond.halloSecond);

                // How can I get glob.vars like the "Saluto!"?
        }
}

© Stack Overflow or respective owner

Related posts about java

Related posts about beginner