क्या कोई यह समझा सकता है कि यह कोड आउटपुट को शून्य के रूप में क्यों दे रहा है? जब मैं new B()
के बजाय new A()
पर कॉल करने का प्रयास करता हूं, तो यह वर्तमान दिनांक प्रिंट कर रहा है।जावा प्रवाह-नियंत्रण
class A
{
Date d = new Date();
public A()
{
printDate();
}
void printDate()
{
System.out.println("parent");
System.out.println(d);
}
}
class B extends A
{
Date d = new Date();
public B()
{
super();
}
@Override
void printDate()
{
System.out.println("child");
System.out.println(d);
}
}
public class Test
{
public static void main(String[] args)
{
new B();
}
}
अच्छा सवाल .. – SonalPM
देखें http://stackoverflow.com/questions/20474521/allowing-the-this-reference-to-escape – Qwerky