I'm a beginner of Java. Recently, I read this code in the Examination database. I supposed "tellName()" and "printName" that will print "base" but I got the result as below. Could you explain why I got this result? Thanks a lot.
public class Dervied extends Base{
private String name = "dervied";
public Dervied(){
tellName();
printName();
}
public void tellName(){
System.out.println("Dervied tell name: " + name);
}
public void printName(){
System.out.println("Dervied print name: " + name);
}
public static void main(String[] args){
new Dervied();
}
}
class Base{
String str = "base";
public Base(){
tellName();
printName();
}
public void tellName(){
System.out.println("Base tell name: " + str);
}
public void printName(){
System.out.println("Base print name: " + str);
}
}
The result:
Dervied tell name: null
Dervied print name: null
Dervied tell name: dervied
Dervied print name: dervied