Guest User

Untitled

a guest
Oct 11th, 2017
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.84 KB | None | 0 0
  1.  
  2. public class Test
  3. {
  4.     private int x;
  5.     private String varNum;
  6.    
  7.     public Test()
  8.     {
  9.         varNum = "1234";
  10.     }
  11.    
  12.     public String getVarNum()
  13.     {
  14.         return this.varNum;
  15.     }
  16.    
  17.     // Main method
  18.     public static void main(String[] args) {
  19.         Test x = new Test();
  20.        
  21.         // Doesn't cause error, but nothing is printed
  22.         x.getVarNum();
  23.        
  24.         // Doesn't cause error, but nothing is printed... again
  25.         String myString = x.getVarNum();
  26.        
  27.         // Doesn't cause error, the value of varNum is printed
  28.         System.out.println( x.getVarNum() );
  29.        
  30.        
  31.         // Causes error - no semicolon at the end
  32.         // x.getVarNum()
  33.        
  34.         // Causes error - no semicolon at the end... again
  35.         // String anotherString = x.getVarNum()
  36.        
  37.         // Causes error - passed arguments inside methods cannot have a semicolon at the end
  38.         // System.out.println( x.getVarNum(); );
  39.        
  40.     }
  41. }
Advertisement
Add Comment
Please, Sign In to add comment