Final keyword with Class and Variable

In this blog, we will work on final keyword with class and variable. Final class can’t inheritance with other class and final variable can’t modify after assign value.

Let’s see both example in one blog

 

Final keyword with Class

final class A

{

                // Create some method

}

class B extends A             // Not possible becuase of final A class

{

                // Create some method

}

class inh8

{

                public static void main(String args[])

                {

                                                B b1 = new B();

                }             

}

Output:

Note: This program generates compile time error.

 

About Programs.

In this program, final class can’t inheritance with other class, so when we run this program, program generate compile time errors.

 

Video available on YouTube.


Final keyword Variable

class inh9

{

                public static void main(String args[])

                {

                                final int x = 10;

                                x++;       // Create an error because of final x variable

                }

}

Output:

Note: This program generates compile time error.

 

About Programs.

In this program, variable x is final so when we increment in x value using x++ that time program gives compile time error in programs.

 

Video available on YouTube.


[sbscrbr_form]

If you have any query on blog example, you can directly comment us or subscribe our website


Earn Money Online

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS

227total visits,1visits today


mayank

Hello, I am Maddy a Java blogger, trainer and developer

Related articles

3 Comments

  1. October 20, 2016 - 5:41 am

    This post is really interesting. I have bookmarked it.
    Do you allow guest post on your blog ? I can write high quality articles for you.
    Let me know.

    • October 20, 2016 - 9:21 am

      Thank you for comment..

      After 1 month we will start guest post in our blog. So you can add your articles after 1 month.

  2. December 1, 2016 - 12:16 pm

    I’m amazed, I have to admit. Rarely do I come across a blog that’s
    both educative and interesting, and let me tell you, you’ve hit the nail on the head.
    The problem is an issue that not enough people are speaking intelligently about.
    I’m very happy that I came across this in my search for something regarding this.

Leave a Reply

Your email address will not be published. Required fields are marked *

Your comments (*)

Name (*)

Your full name please.

Email address (*)

Used for gravatar.

Website

Link back if you want.

EmailEmail
PrintPrint