Ethan wrote:
> I have a requirement where base class has method (implemented) and
> derived class shouldn't be able to override it.
> However, the method needs to be invoked by a caller who creates an
> instance of the derived class.
>
> Is this possible?
Absolutely.
You prevent an override by 'final' in the method signature, and this is very frequently The Right Thing To Do.
You make the method callable by client code through 'public' in the method signature, which is the standard thing to do.
public class BaseOfOperations
{
public final void DoSomething()
{
// implementation here
}
}
public class SpecificOperations extends BaseOfOperations
{
// cannot override DoSomething()
}
public class Client
{
public void Whatever()
{
BaseOfOperations boo = new SpecificOperations();
boo.DoSomething();
}
}
I suggest that you read the Java tutorials and a good basic book on Java programming.
http://download.oracle.com/javase/tutorial/
--
Lew