Guest User

Untitled

a guest
May 15th, 2018
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 0.77 KB | None | 0 0
  1. package com.vk.vitalypavlenko.newSandbox;
  2.  
  3.  
  4. public class MethodInnerClassTest {
  5.  
  6.     static Object someReference;
  7.    
  8.     public void Method(int z) {    
  9.         final int y = z;
  10.        
  11.         class Inner {          
  12.             int x;
  13.            
  14.             Inner(int x) {
  15.                 this.x = x;
  16.             }
  17.            
  18.             public String toString() {
  19.                 return "hi, i'm Inner, my x is " + x +
  20.                     " and y in my method is " + y;
  21.             }
  22.         }
  23.        
  24.         if (someReference == null) {
  25.             someReference = new Inner(42);
  26.         } else {
  27.             System.out.println((Inner) someReference);
  28.             System.out.println("But actually y is " + y);
  29.         }      
  30.     }
  31.    
  32.     public static void main(String[] args) {
  33.         MethodInnerClassTest mict = new MethodInnerClassTest();
  34.         mict.Method(1);
  35.         mict.Method(2);
  36.         someReference = null;
  37.         mict.Method(3);
  38.         mict.Method(4);
  39.     }
  40.  
  41. }
Add Comment
Please, Sign In to add comment