You are here: Home / Topics / Program to explain final method restricts in Java

Program to explain final method restricts in Java

Filed under: Java

//  Program to explain final method restricts 
//  (not allow) the overriding of that method

class  A
{
final void display()
{
 System.out.println(" A\'s display().");
}
}

class  B extends A
{
// final method can't be override.
// void display()
void show()
{
 System.out.println(" B\'s display().");
}
}

class  FinalMethod
{
public static void main( String args[ ] )
{
 B b = new B();
 b.display();
 b.show();
}
}

 

Output:

A's display().
B's display().

Categories