What change shuld be made to this code to make it compile and give i=4 (Also the class A does not have a constructor) class A { int i; A(int i) { this.i = i * 2; } } class B extends A { public static void main(String[] args) { B b = new B(2); } B(int i) { System.out.println(i); } }
Faiza, 1)Create a constructor A(){} 2)Make the return type int for A(int i) method 3)In B(int i), add this line super.A(i)
class A { int i; A(){ }; int A(int i) { this.i = i * 2; return i; } } class B extends A { public static void main(String[] args) { B b = new B(2); System.out.println(b.i); } B(int i) { super.A(i); } } thanks kiran
Without subsidies, chem-ag food costs four times more than organic. Or this tiny ad:
a bit of art, as a gift, the permaculture playing cards