Thanks aliteralmind but I don't understand how that would allow me to do something like:
arrObjects[2].doSomething();
Type: Posts; User: Wice
Thanks aliteralmind but I don't understand how that would allow me to do something like:
arrObjects[2].doSomething();
Well, I could have a Team object, inside it is an array with Player objects. There could be 3 players but there just as well could be 11 players. At some point I want to call a method from every...
Well, I was working on something that could call a method of an object without calling a specific object by its name.
I think I was thinking too much in a PHP way, I changed the array from a string type, to a TestThing type and got it working like this:
public class Test {
public static void main(String[]...
arrObjectNames[0] = "objFirst";
arrObjectNames[1] = "objSecond";
arrObjectNames[2] = "objThird";
TestThing objFirst = new TestThing();
TestThing objSecond = new TestThing();...
Whoops, my bad, sorry. It still doesn't work though
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method doSomething() is undefined for the type String
...
Alright, this is my very short example code:
public class TestThing {
public void doSomething(){
System.out.println("succes");
}
}
Sorry to ask this before trying but I'm not currently behind my computer:
Say I make a new variable, call it targetBook and give it a value of "bookA"
would targetBook.methodName(argsToMethod)...
Thanks, my second question could be asked in a more simple way I guess: How can I call a method from an object based on a variable object name?
Hello,
I've been searching quite a while for an answer but seeing as I could not find it, I decided to come here, hoping someone could help me.
Say I have two classes, Author and Book, and I...