What will be the result when the following code is compiled and executed?

final public class Parent {
    final public void test() {            

class Child extends Parent {         //1
    public void test() {             //2

class Main {            
    public static void main(String args[]) {
        Child c = new Child();
In this case, the final keyword is used to override the parent class inheritance and non-override method test ()

javac Parent.java

Parent.java:7: cannot inherit from final Parent
class Child extends Parent { //1
Parent.java:8: test() in Child cannot override test() in Parent; overridden method is final
public void test() { //2
//2 errors

Follow CodeGalaxy

Mobile Beta

Get it on Google Play
Send Feedback
Keep exploring
Java quizzes
Sign Up Now
or Subscribe for future quizzes