I know it is early ... But, i am Why does the following program produce 'null'. public class testA { String s; public static void main(String argv[]){ testA m = new testA(); m.go(); } // end of main void testA() { s = "Constructor"; } // end of constructor void go() { System.out.println(s); } // end of go method } // end of class testA Help Monty6,
The problem lies with the fact that a default no-arguement constructor is used (not the one you THINK you've used. )Constructors cannot be void. Therefore s is never initialised. Hope this helps
Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
So, what your saying is that the JVM is giving me a default constructor. Because void testA() is a method. Question: What is the signature of a constructor? Still
No problem. I often find that I often get so caught up in the complexities of java that the basics can easily be overlooked. I have to admit, it had me stumped for a while!!
Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
a constructor cannot have a return type so void is not allowed . it creates another method in the same class with a return type of void and the same name as the class .
------------------
Don't get me started about those stupid light bulbs.