How does inheritance of instance fields work in this particular code?

后端 未结 10 1687
我寻月下人不归
我寻月下人不归 2020-12-24 11:11
class A
{
    int a = 2, b = 3;
    public void display()
    {
        int c = a + b;
        System.out.println(c);
    }
}
class B extends A
{
    int a = 5, b =          


        
10条回答
  •  心在旅途
    2020-12-24 11:29

    There isn's anything called variable overriding. That is why you are getting the same result in both the cases.

提交回复
热议问题