Why is the output different in the two cases?

前端 未结 3 1934
慢半拍i
慢半拍i 2021-01-22 06:10

Why is the output different in the below case even when, the variable has been overridden?

public class A {
    int a = 500;

    void get() {
        System.out         


        
3条回答
  •  -上瘾入骨i
    2021-01-22 06:26

    No the variable is not overridden. ob.a print the a variable of B class. ob.get() searches for the get method in B class.when it does not gets there it then searches the parent class and executes it.

提交回复
热议问题