Advertisement
AnindyaBiswas

immu

May 19th, 2022
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.59 KB | None | 0 0
  1. import java.util.Scanner;
  2. public class immu{
  3.     public static void main(String Args[])
  4.     {
  5.         immu_demo obj = new immu_demo(1,2);
  6.         //obj.set1(3);
  7.         System.out.println("private variables " + obj.get_var1() + " " +" "+ obj.get_var2());
  8.      
  9.     }
  10. }
  11.  
  12. class immu_demo {
  13.     private final int var1, var2;
  14.  
  15.     immu_demo(int a, int b)
  16.     {
  17.         System.out.println("Constructor called");
  18.         var1 = a;
  19.         var2 = b;
  20.     }
  21.  
  22.     int get_var1()
  23.     {
  24.         return var1;
  25.     }
  26.    
  27.     int get_var2()
  28.     {
  29.         return var2;
  30.     }
  31.    
  32.     //void set1(int a) {var1 = a;}
  33. }
  34.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement