You can prevent others from extending your class by making it final using the keyword final in the class declaration.
final class FinalClass{
}
Using final to Prevent Overriding
class A {
final void meth() {
System.out.println("This is a final method.");
}
}
class B extends A {
void meth() { // ERROR! Can't override.
System.out.println("Illegal!");
}
}
http://www.java2s.com/Tutorial/Java/0100__Class-Definition/Catalog0100__Class-Definition.htm
No comments:
Post a Comment