Question: How can I take the output of a while loop and pass it to a for loop?

I get some id from my sql db using while loop. Now, how to pass each id to select query?

For example:

```
while($row = mysql_fetch_array($sql)) {
    $y= $row['c'];
} 

```

How can I pass each $y to a select query?

Answer: 
There's no way to do this in Java.

Your two options (one which you mentioned) are using public getters and making the field private, or thorough documentation in the class.

The overhead on getter methods in extremely small (if at all). If you're doing it a large number of times, you might want to cache the fetched value instead of calling the get method.

EDIT:

One way to do it, although it has even more overhead than the getter, is defining a public inner class (let's call it `innerC`) with a constructor that is only available to your `C` class, and make your fields public. That way, you can't create `innerC` instances outside your class so changing your fields from outside is impossible, yet you can change them from inside. You could however read them from the outside.
yes.. we can make a variable read-only using **final** keyword

Ex: `public final int id = 10;`