hi,
Explain me below code.
class Phone {
String device = "Phone.device";
void showDevice() {
System.out.println("Phone.showDevice," + device + " ");
}
Phone() {
System.out.println("Phone construtor");
showDevice();
System.out.println("Phone construtor end");
}
}
class Mobile extends Phone {
String device = "Mobile.device";
void showDevice() {
System.out.println("Mobile.showDevice," + device + " ");
}
Mobile() {
showDevice();
}
public static void main(String[] args) {
Phone n = new Mobile();
n.showDevice();
}
}
output is :
Phone construtor
Mobile.showDevice,null//why Mobile device is called?why it prints null?
Phone construtor end
Mobile.showDevice,Mobile.device
Mobile.showDevice,Mobile.device