Final Variables and Methods



All methods and variables can be overridden by default in subclasses. If we sish to prevent the subclasses from overriding the members of the superclass, we can declare them as final using the key word final as a modifier .

Example:

final int size=100;

final void show(){…….}

Making a method final ensures that the functionality defined in this method will never be altered in any way. Similarly, the value of a final variable can never be changed. Final variables, behave like class variables and they do not take any space on individual objects of the class

Random Posts

  • Define Connection Pooling
  • How to run a Java web application
  • Define EJB frame work
  • Uploading file name or image to DataBase
  • Explain session destroy in Servlets

Post a Comment