I have a code as below:
Class A{
protected void method1(){
//i have logic which will fetch the results from the database
}
}
and i have one more class which extends the class A:
Class B extends A{
//some logic
}
Now how many database calls are executed? one or two?
If you do:
method1()is called exactly once on behalf ofBobject. What the JVM is doing is it tries to findB.method1()first. If it was overriden inB, it would call it (and completely skipA.method1()). But sinceBis not overriding it, originalA.method1()is called transparently.If
Bwould overridemethod1()the only way to call originalA.method1()would be to callsuper.method1()insideB.