0
I’d like to know why the code compiles but does not execute?
Follows the code:
package exemploinicializador2;
public class ExemploInicializador2 {
private String nome = "Aurélio";
private String sobrenome = "Soares";
private int idade = 25;
private double f = 354.34;
// Bloco Inicializador
{
System.out.println ("Nome: " +nome);
System.out.println ("Sobrenome: " +sobrenome);
System.out.println ("Idade: "+idade);
System.out.println ("F: "+f);
}
// Construtor
public ExemploInicializador2 () {
System.out.println ("Dentro do Construtor");
}
}
The other code is:
package exemploinicializador2;
public class TesteInicializador2 {
public static void main (String args []) {
TesteInicializador2 objeto = new TesteInicializador2();
}
}
Which of the two does not execute? Both must execute, only in the first does not have the main and in the second there is nothing to display.
– user28595
The first class is never instantiated. If it does not instantiate, it will not display anything at all.
– user28595
Did the answer help you? If yes, you can mark it as accepted by clicking on
v
the left of the answer :)– user28595