There’s a Java program:
public class Constructors { private static class Parent { public Parent() { test(); } public void test() { System.out.println("Hello from Parent"); } } private static class Child extends Parent { private String name; public Child() { name = "Hi"; } @Override public void test() { System.out.println("Hello from child " + name); } } public static void main(String[] args) { new Child(); } }
What does it print?
The answer is obvious if you compile and run it? Can you answer it without running?
September 8, 2011 at 15:47
This code would not compile 🙂
September 8, 2011 at 15:56
The code is correct, it compiles and even prints something.
September 9, 2011 at 09:22
Yes, my bad. Messed out… 🙂
It will print “Hello from child null”
September 9, 2011 at 10:04
Yes, exactly.
November 10, 2011 at 23:54
[…] and a half months ago I posted a question on Java. Now it’s time for its counterpart in […]