Domanda The method x is undefined for the type y

Stato
Discussione chiusa ad ulteriori risposte.

clich

Utente Electrum
9 Marzo 2012
225
48
27
147
Ciao ragazzi vi posto subito il codice del progetto, l'errore è il seguente The method getName() is undefined for the type Studente.

Classe.java
Codice:
public class Classe {


	/**
	 * Classe che contiene il punto di partenza del programma
	 * 
	 * Crea oggetti utilizzando il metodo Studente
	 * 
	 *
	 */
	
	public static void main(String[] args) {
		
		Studente alunno1 = new Studente("Luca", 18);				
		Studente alunno2 = new Studente("Andrea", 16);
		
		System.out.println("Alunno: " + alunno1.getName() + ", " + alunno1.getEta());
		System.out.println("Alunno: " + alunno2.getName() + ", " + alunno2.getEta());
	}


}

Studente.java
Codice:
public class Studente {


	/**
	 * Modello per istanziare più studenti
	 * 
	 * [MENTION=7441]para[/MENTION]m args
	 */
	
	public String nome;
	private int eta;
	
	public Studente(String nome, int eta) {
		this.nome = nome;
		this.eta = eta;
	}
	
	public String getNome() {
		return nome;
	}
	
	public int getEta() {
		return eta;
	}
	
	public void setNome(String nome) {
		this.nome = nome;
	}
	
	public void setEta(int eta) {
		this.eta = eta;
	}
}
 
Ti sei semplicemente dimenticato di aver scritto getNome() invece di getName()
Di conseguenza
Codice:
System.out.println("Alunno: " + alunno1.getName() + ", " + alunno1.getEta());
		System.out.println("Alunno: " + alunno2.getName() + ", " + alunno2.getEta());
Va modificato in
Codice:
System.out.println("Alunno: " + alunno1.getNome() + ", " + alunno1.getEta());
		System.out.println("Alunno: " + alunno2.getNome() + ", " + alunno2.getEta());
 
  • Mi piace
Reazioni: uerreelle
Stato
Discussione chiusa ad ulteriori risposte.