I called a method to set the hour and store it in a files in the object called recardObj, but when i go and pull try and print the stored value from the field I get back 0.
Can anyone tell me how to keep this object in scope.
You are setting the hour on one object, and getting it on another object. This is not a scoping issue. Your currentHour() method should return the object on which you have set the hour, so that the main method can get the hour from that object.
Another thing, if you're working with time, please don't use Calendar, but use the new java.time classes.
Alex Lucard wrote:I added this to the class recardObj
Now in netbeans i get this error on the line with the new code "Incompatible type: int connot be converted to RecordObj …."
"public RecordObj returnCurrentHour()"
Let's take this method signature and examine it. First it is "public" which means anyone can call it. So far so good. Second, it's return type has been set to "RecordObj." Is that what you wanted to do? Third, it is named "returnCurrentHour()" suggesting you want to return the current hour. What type is the currentHour variable? Does it match the return type of the method? This is what the compiler is trying to tell/ask you.
Then can you show me how to access the same object in multiple classes.
1) I would like to make a class and turn it into an object called Obj. like a getters and setters
2) Next make a new class lets call this class A and store a value in one of the fields in the Obj getters and setters.
3) Then make a new class called class B and access the values from the Obj class and print them out.
That is all I am looking for is how to pass values into a object from one class and access that same object from other classes.
Can someone show example code or tell me what I need to change in my code to make this work.
You say that you want to create an object, but you can't do this without context. Where is the object created? If you want to do all of this in the same method, you first create the object using the new keyword, then you pass it to the appropriate method of class A, and then you pass it to the appropriate method of class B.
Your original code differs from this in that you first call the method of A which creates its own object. You should first create r, and then pass it to currentHour().