Interview Question

Interview Burlington, MA

This isn't really the most difficult question i've ever

  heard but... Say you have the following classes class A { public String doIt() { return "A"; } } class B extends A { public String doIt() { return "B"; } } class C { public static String doIt() { return "C"; } } class D extends C { public static String doIt() { return "D"; } } Now consider the following code snippet A b = new B(); String s1 = b.doIt(); C d = new D(); String s2 = d.doIt(); What will be the values of s1 and s2?
Answer

Interview Answer

2 Answers

0

The answer lies in basic understanding of difference between static and virtual functions.

Interview Candidate on Dec 26, 2011
0

The answer is s1 = B and s2 = D

Anonymous on Nov 13, 2014

Add Answers or Comments

To comment on this, Sign In or Sign Up.