TODAY JAVA SCHOOL

In java school, programming, design, computer general knowledge, web application, software, web services, social media, digital marketing, oops, concept of programming language, oops feature, console media, graphics medium, first programming, c, c ++ , Java, PHP, SQL, MySQL, HTML, HTML_5, J_query, JavaScript, Bootstrap, Framework, images with logos, examples, shared and explained.

https://www.amazon.in/b?node=26373545031&linkCode=ll2&tag=1234567801cdb-21&linkId=3b9882431b00409b44141e0344b35a15&language=en_IN&ref_=as_li_ss_tl

Breaking

Wednesday, 5 February 2020

final method in java | java final variable in method

Final method in Java

The final modifier for finalizing the implementations of classes, methods, and variables.
We can declare a method as final, once you declare a method final it cannot be overridden. So, you cannot modify a final method from a sub class.
The main intention of making a method final would be that the content of the method should not be changed by any outsider.

static java final variable in method
final method in java programming

Example:

public class FinalMethodExample {
   public final void display(){
      System.out.println("Hello welcome to Tutorialspoint");
   }                        
   public static void main(String args[]){
      new FinalMethodExample().display();
   }
   class Sample extends FinalMethodExample{
      public void display(){
         System.out.println("hi");
      }
   }
}

Output:

FinalMethodExample.java:12:error:display()  in
FinalMethodExample.Sample cannot override display() in
FinalMethodExample
public void display() {
overridden method is final
1error

No comments:

Post a Comment