Why, using same String name variable in every class gives the name null except the last child class ( cinematographer)?
public class Filmmaker { String name; public void direct() { System.out.println(" Director " +name+ " is Directing A Clockwork Orange \n"); } public void write() { System.out.println(" writer " +name+ " Is writing The Royal Tenenbaums \n"); } public void produce() { System.out.println(" Director " +name+ " produced his own films \n"); } } public class Composer extends Filmmaker { String name; public void compose() { System.out.println(" Legend " + name+ " is composing Love theme from Cinema Paradiso \n"); } } public class Cinematographer extends Composer { String name; public void visualise() { System.out.println(" Legend " +name+ " is filming Y tu Mama Tambien \n"); } } public class Legends extends Cinematographer { public static void main(String[] args){ Legends l=new Legends(); l.name=" Stanley Kubrick "; l.direct(); l.name=" Wes Anderson "; l.write(); l.name=" Stanley Kubrick "; } }