Search This Blog

Monday, 27 January 2014

using "final" keyword in Java

/* program to illustrate final keyword */

package finalkeyword;
class Parent //final class cannot be inherited.
{
   final int r=5;
   final void show()
   {
//       r=7; cannot be re defined because it is decalred as final
      System.out.println("Final method executes ...");
   }
}
class Child extends Parent
{
//    void show() method cannot be override because it is final in parent class
//    {
//       
//    }
   
}
class MainClass
{
    public static void main(String[] args)
    {
        Child c=new Child();
        c.show();
    }
}

output

No comments:

Popular Posts