You are writing
a method that is declared not to return a value.
Which two are permitted in the method body?
Which two are permitted in the method body?
A.
omission of the return statement
omission of the return statement
B.
return null;
return null;
C.
return void;
return void;
D.
return;
return;
Risposta: A e D
Un metodo void non può restituire nulla, quindi sia null che void non sono permessi. Può invece contenere dei return che servono ad uscire al flusso logico del metodo, ad esempio:
public class main {
public static void main(String[] args) {
int pippo=4;
stampa(pippo);
}
public static void stampa(int a) {
if(a==4){
System.out.println("esco
prima");
return;
}
System.out.println("esco
dopo");
return;
}
}
Nessun commento:
Posta un commento