Sarah P.

asked • 09/05/20

Can I have help with this problem?

Predict what will be printed out on console, if you run class 'Test' below?


public class Test {

public static void main(){String[] a){

A ref = new B();

ref.mP();

}

}

protected int f = 1;

public void mP(){

System.out.println("100");

mQ();

mR();

}

public void mQ(){

System.out.println(f);

mR();

}

private void mR(){

System.out.println(f);

}

}

public class B extends A {

protected int f = 2;

public void mP(){

System.out.println("101");

super.mP();

}

public void mQ(){

System.out.println(f);

super.mQ();

}

public void mR(){

System.out.println(f);

}

}

public class A {

1 Expert Answer

By:

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.