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

Program to explain final method restricts in Java

Filed under: Java on 2023-09-17 07:10:08

//  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().

About Author:
S
Shyam Dubey     View Profile
If you are good in any field. Just share your knowledge with others.