Recommended: Sing it, brah! 5 fabulous songs for developers
JW's Top 5
This is a really, really dumb question but I'm trying to wrap my mind around why all my beginner java books use the main method to instantiate objects of a different class than the one it is being instantiated in, such as the one below. I've tested it and know it works but why don't I ever see it in the books? Is there a drawback to creating a new object of the same object that you are in?
Thanks, Von and sorry if this is a crazy question!!!!!!
public class TestClass
int id = 6;
{
public static void main(String[] args)
{
TestClass firstTest = new TestClass();
firstTest.id = 5;
System.out.println(firstTest.id);
}
}