Share this post on:

Final keyword in Java is a special type of Modifier which is used to restrict the user. final keyword can used while declaring an entity. final keyword can be used by three ways?

  1. Final Data Member
  2. Final Method
  3. Final Class

Final Data Memeber : Final Data member can not be reinitialised if that data member is associted with final Keyword.

Ex: write a Java Program to demonstrate Final Data Member?

Final Method : Final Method is a simple method just associte with the final keyword. Final methid can not be override in subclass.

Example: write a Java Program to Demonstrate Final method

class TestDemo 
{	

	public void first()
	{
		System.out.println("Hello");
	}
	
	public final void second()
	{
		System.out.println("Hi");
	}
}
	public class Example extends TestDemo
	{
		public void first()
		{
			System.out.println("Hello");
		}
		
		public void Second()
		{
			System.out.println("Hi");

		}
		
	public static void main(String[] args)
	{
	
	}
}
public void first()
{
    System.out.println("Hello");
}

public final void second()
{
    System.out.println("Hi");
}
}
public class Example extends TestDemo
{
public void first()
{
System.out.println("Hello");
}
public void Second()
    {
        System.out.println("Hi");

    }

public static void main(String[] args)
{

}
}

Final Class: When a Class is associated with final is known as final class. Final Class can not extends.

Share this post on:
Avatar Raiyan

Author: Raiyan

Hi, I guess you're here because you want to know a bit about me. huh? I am not so good on talking about myself but I'll give a short about me.

My Name is Raiyan. I am a Professional Application Developer and a Blogger.
I started this website to Share my Knowledge. Here I provide all my knowledge whatever I earned till now.

Leave a Comment

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