vendredi 6 mars 2015

Get nth object in class Java



If I have this code:



public class Foo{
public static void main(String[] args){
String hello = "Hello World";
int num = 7;
}
}


And if I wanted to print out String hello and int num, I would normally do:



System.out.println(hello);
System.out.prinln(num);`


However, can I access hello and num in a different way, like:



Foo(0); // for String hello
Foo(1); //for int num



Aucun commentaire:

Enregistrer un commentaire