Determine the result of attempting to compile and run the following code: class A { public int Avar; public A() { System.out.println("AAA"); doSomething(); } public void doSomething() { Avar = 1111; System.out.println("A.doSomething()"); } } public class B extends A { public int Bvar = 2222; public B() { System.out.println("BBB"); doSomething();
} public void doSomething() { System.out.println("Bvar=" + Bvar); } public static void main(String[] args) { new B(); } } The output is: AAA Bvar=0 BBB Bvar=2222
My questions are: why "A.doSomething()" is not output? Why "Bvar=0"?
Benben Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy. Thanks again and we hope to see you around the ranch!!
Dave
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.