I have an entire program wrote, but I'm having problems with the getMethod. I need a get method which will receive the position of the variable (1,2, or 3) and will then return the variable at that position. Here's an example of the call to the method: System.out.println(dog.getFido(2));

I've tried multiple variations, but none of the codes have worked. Can someone point me in the right direction. I've looked for tutorials and examples of this online, but I not even sure I'm using the right keywords for the search.

I appreciate any help you can give me.

Thanks!

Recommended Answers

All 2 Replies

I need a get method which will receive the position of the variable (1,2, or 3) and will then return the variable at that position.

Sounds like an application for an array. Change the word "position" to index and 'variable' to element and you're talking about arrays.
An array holds elements. Each element is at an index position, starting from 0 to the number of elements minus 1.
elementAtOne = theArray[1]; // returns variable/element at position/index one

Ah I was wondering why his getFido method included a parameter. Good call on the array. It might be in your best interest to post part the code in question if you are still confused or your question was not answered!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.