fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. String test = "Hello from main";
  14. System.out.println("From main method: " + test);
  15. stringTest(test);
  16. System.out.println("From main method: " + test);
  17. stringConcatTest(test);
  18. System.out.println("From main method: " + test);
  19.  
  20. }
  21.  
  22. // string reassignment inside a method
  23. public static void stringTest(String something) {
  24. something = "Hello from the method";
  25. System.out.println("Inside the method: " + something);
  26. }
  27.  
  28. // string concatenation inside a method
  29. public static void stringConcatTest(String something) {
  30. something = something + " and concatenated inside the method";
  31. System.out.println("Inside the concat method: " + something);
  32. }
  33. }
Success #stdin #stdout 0.1s 36180KB
stdin
Standard input is empty
stdout
From main method: Hello from main
Inside the method: Hello from the method
From main method: Hello from main
Inside the concat method: Hello from main and concatenated inside the method
From main method: Hello from main