Write a program in java to demonstrate final data member?

class Find

{

                public static void main(String arg[])

                {

                                int a=5;

                                a=7;

                                System.out.println(a);

                }

}

Without Final Data Member.PNG

class Find

{

                public static void main(String arg[])

                {

                                final int a=5;

                                a=7;

                                System.out.println(a);

                }

}

Note – Its gives error because final data member cannot be reinitialized.

Final Data Member.PNG

, , , , , , ,

Leave a Reply