What is the result of the following code fulfillment:

class A {
    public void m(int k) {
        System.out.println("class A, method m : " + ++k);
    }
}

class B extends A {
    public int m(int k) {
        System.out.println("class B, method m : " + k++);
        return k;
    }
}

public class MainClass {
    public static void main(String args[]) {
        A a = new B();
        a.m(34);
    }
}
Explanation
Explanation: in the methods void m(int k) Class A and int m(int k) Class B the types of the returned values don't match, which causes a compiler error.

Follow CodeGalaxy

Mobile Beta

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