Why object is not being instantiated?

0

I have a Bean class ( Casa.java )

public class Casa{
      //atribubutos

      private String parede;

      public Casa(){
      }
      //getters e setters
      public void setParede(String parede){
             this.parede = parede;
      }
      public String getParede(){
             return parede;
      }
}

I'm trying to instantiate it in another class as in the example

public class testeCasa(){

       public static void main(String[] args){

          String erro="";
           try{
              Casa casa = new Casa();

              casa.setParede("Parede Sul");
              System.out.println(casa.getParede());
              }
           }catch (Exception e{

                  erro = e.getMessage();
           }finally{
                  System.out.println(erro);
           }
}

Only when I run debug , it arrives at the Casa casa = new Casa(); excerpt "and stops the program nor does it continue pro casa.getParede(); and goes straight to finally by printing the error as" ". What can it be?

    
asked by anonymous 15.10.2015 / 17:01

1 answer

4

Your code does not compile, so every description of the question and comment is not true. When it solves the problems that prevent compilation the code works perfectly, although it is not doing anything very useful. But if the goal was to assign a value to the property and then print it by taking value from it, this is occurring.

class Casa {
    private String parede;
    public void setParede(String parede) {
        this.parede = parede;
    }
    public String getParede() {
        return parede;
    }
}

class Ideone {
    public static void main(String[] args) {
        String erro="";
        try {
            Casa casa = new Casa();
            casa.setParede("Parede Sul");
            System.out.println(casa.getParede());
        } catch (Exception e) {
            erro = e.getMessage();
        } finally {
            System.out.println(erro);
        }
    }
}

See running on ideone . (I had to remove the public just to meet the ideone's need.

The builder is absolutely unnecessary in this case. The try-catch also seems to be, but you may be wanting to test or learn something from it.

    
15.10.2015 / 18:17