Chi mi puo spiegare il motivo dell'output di questo esempio??
perchè esce null?? e su student fred??codice:public class Student { public String name; …} public class GradStudent extends Student { String name; // adombramento del campo della superclasse public GradStudent(String name) {this.name = name; } void twoNames() { System.out.println(”Student: " + name); System.out.println(”Grad Student: " + super.name); } public static void main (String [] args){ GradStudent fred = new GradStudent("Fred"); fred.twoNames(); } } Output: Student: fred Grad Student: null
Student: fred
Grad Student: nul

Rispondi quotando