Friday, November 20, 2015

Program to demostrate final keyword.

class Base
{
final void show()
{
System.out.println("Base class Method");
}
}
class Derived extends Base
{
void show()
{
System.out.println("Derived class Method");
}
}

class FinalMethod
{
public static void main(String args[])
{
Derived obj=new Derived();
obj.show();
}
}
Output:
 error: show() in Derived cannot override show() in Base

No comments:

Post a Comment