Simple Question (I Think...?)
Okay so this is probably really simple, but I am trying to make one class called builder create a copy of another class called house, and then return it to my main function.
public House buildHouse()
{
House h1 = new House();
return h1;
}
That is currently the code for the function.
My problem is that while i am returning house h1 to the main function, my next functions in my main function are supposed to interact with this house, and i am getting errors as if the code cannot find house h1. It doesn't seem complicated and I'm almost positive it isn't but I would really appreciate any help.
Re: Simple Question (I Think...?)
I'm sorry i didn't mean a copy of the class house, I meant I wanted to create an object of the house class and then return it to my main class, a bit new to java and I didn't think through my terminology before posting.
Re: Simple Question (I Think...?)
Post your main method, as the syntax you've used for your buildHouse is correct.
Re: Simple Question (I Think...?)
Code Java:
//
b1.buildHouse();
h1.setOccupant(b1);
System.out.println(h1.getOccupant());
the error that comes up is
h1 cannot be resolved
I know all of my functions work correctly because if I create a House object in the main function all of it works fine. It's just pulling this house out of another function that is giving me trouble.