Java program to implement use of Final Keyword on Class, Method and Variable

Simple Java program to use Final Keyword on following items:

  • Variable
  • Class
  • Method

Code:


class a{

final int a=5;

void setfinala(int x)

{

a=x;

}



final void finalmethod()

{ System.out.println("Final method.");

}

}



class a1 extends a{



void finalmethod()

{

System.out.println("Final method in extended class.");

}

}



final class b{

}



class c extends b{

}



class p33{

public static void main(String args[]){

a obj = new a();

a.setfinala(3);

}

}

Note: The program won't run because of error and that error is output of our program.





Comments

Popular posts from this blog

C program to evaluate Prefix Expression using Stack data structure

Servlet Program to Print Today’s Date and Time using refresh header

Java Program to Implement sorting algorithm using TCP on Server application