So, we continue the excursion into the Java-problems. Another of the same sources, however, it may seem very simple for experienced or for those who have a compiler at hand.
Code:
public class A { public A() { myMethod(); } public void myMethod() { Date date = new Date(); } } public class B extends A { private Date date = new Date(); public B() { date = new Date(); } @Override public void myMethod() { System.out.println(date); } //... public static void main(String[] args) { B sub = new B(); sub.myMethod(); } } Questions:
- What is the output of this program?
- Explain your previous answer
For OOP learners, the task will be very useful. In addition, you can add your thoughts on why this program is not fail-safe (robust).