Java final method

Java final method

If you make any method as final, you cannot override it.

Example of final method

  1. class Bike{  
  2.   final void run(){System.out.println("running");}  
  3. }  
  4.      
  5. class Honda extends Bike{  
  6.    void run(){System.out.println("running safely with 100kmph");}  
  7.      
  8.    public static void main(String args[]){  
  9.    Honda honda= new Honda();  
  10.    honda.run();  
  11.    }  
  12. }  
Output: Compile Time Error


Comments

Popular posts from this blog

Handling Dynamic Web Tables Using Selenium WebDriver

Verify Specific Position of an Element

Read it out for TESTNG before going for an iterview