1

I am trying to understand the output of the java toy program below...

public class BaseWithPrint {

    public BaseWithPrint(){
        print();
    }

    public void print(){
        System.out.println("BaseWithPrint.print");

    }
}

class DerivedWithPrint extends BaseWithPrint{
    int i = 47;
    public void print(){
        System.out.println("i = " + i);
    }
}

class Initialization_MYCLASS{
    public static void main(String args[]){
        DerivedWithPrint dp = new DerivedWithPrint();
        dp.print();
    }
}

The output of this file is:

i = 0
i = 47

I understand why I get the second line. But is the first line i = 0?

Sotirios Delimanolis
  • 274,122
  • 60
  • 696
  • 724
RetroCode
  • 342
  • 5
  • 14

0 Answers0