There are two classes:

package pak1;
import pak2.B;
public class A {
	void doAThings() {
		System.out.print("A ");
	public static void main(String[] args) {
		A a = new B();

package pak2;
import pak1.A;
public class B extends A {
	public void doAThings() {
		System.out.println("I'm B ;)");
What will happen when you try to compile both classes and run the main-method?
doAThings method is not inherited by class B, because B is in other package, and the access modifier in doAThings is absent (package-private). Therefore, polymorphic call of doAThings will not happen. Method doAThings will be called from class A.

Слідкуй за CodeGalaxy

Мобільний додаток Beta

Get it on Google Play
Зворотній Зв’язок
Продовжуйте вивчати
тести з Java
Зареєструйся Зараз
або Підпишись на майбутні тести