USE OF FINAL KEYWORD

This section of JAVA contains source codes of many different type of Java Programs to learn the JAVA Basics. These Programs are well formatted and easy to understand.

USE OF FINAL KEYWORD

Postby aman_1982_2006 on September 4th, 2008, 5:51 am

Code: Select all
//use of final keyword
class room
{
   int l,b;
   room(int x,int y)
   {
      l=x;b=y;
   }
   final void volume()
   {
      System.out.println(l*b);
   }
}
class bedroom extends room
{
   int h;
   bedroom(int x,int y,int z)
   {
      super(x,y);
      h=z;
   }
   void volume()//method cannot be overriden as
   //it is declared as final in base class, error
   {
      System.out.println(l*b*h);
   }
}
class mn6
{
   public static void main(String args[])
   {
      bedroom b1=new bedroom(4,5,2);
      b1.volume();
      b1.volume();
   }
}   
aman_1982_2006
 
Posts: 9
Joined: August 30th, 2008, 6:18 am

Return to Java

Who is online

Users browsing this forum: No registered users and 0 guests

cron