1.

Is this program giving a compile-time error? If Yes then state the reason and number of errors it will give. If not then state the reason.

Answer»

abstract final class InterviewBit{2. public abstract void printMessage();3. }4. class ScalarAcademy extends InterviewBit{5. public void printMessage(){6. System.out.println("Welcome to Scalar Academy By InterviewBit");7. }8. }9. class ScalarTopics extends ScalarAcademy{10. public void printMessage(){11. System.out.println("Welcome to Scalar TOPICS By Scalar Academy");12. }13. }public class Main{ public static void main(String[] args) { InterviewBit ib = new ScalarTopics(); ib.printMessage(); }}

The above PROGRAM will give a compile-time error. The compiler will THROW 2 errors in this.

  • [Illegal Combination of modifiers: abstract and final] at line 1.
  • [Cannot inherit from final ‘InterviewBit’] at line 4.

It is because abstract classes are INCOMPLETE classes that need to be inherited for making their concrete classes. And on the other hand, the final keywords in class are used for avoiding inheritance. So these combinations are not ALLOWED in java.



Discussion

No Comment Found