If class B extend A then will it gives output 1 or what happens
class A{ public static class GreenHouse{ int x=1; } public GreenHouse gh; A(GreenHouse gh){ this.gh=gh; } public GreenHouse getGreenHouse(){ return gh; } } public class B{ public static class GreenHouse{ int x=2; } public static void main(String args[]){ A a=new A(new GreenHouse()); System.out.println(a.getGreenHouse().x); } }
I can give you a straight answer, but since you are signed up to our course, I want to make sure there are no lapses in your understanding. So, can you please tell me why you thought making the class B extend A would make a difference?