Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.Scanner;
- public class immu{
- public static void main(String Args[])
- {
- immu_demo obj = new immu_demo(1,2);
- //obj.set1(3);
- System.out.println("private variables " + obj.get_var1() + " " +" "+ obj.get_var2());
- }
- }
- class immu_demo {
- private final int var1, var2;
- immu_demo(int a, int b)
- {
- System.out.println("Constructor called");
- var1 = a;
- var2 = b;
- }
- int get_var1()
- {
- return var1;
- }
- int get_var2()
- {
- return var2;
- }
- //void set1(int a) {var1 = a;}
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement