This week's book giveaway is in the OCAJP 8 forum. We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line! See this thread for details.
It isn't give the any Type of Exception, instead of it dispaly null , 0 (nul for instance t(Object) and 0 for i) their default value. After that line(line 5), It's give some kind of unknown exception. Here we are creating an Object with the name as t in the main method. It (the Object t) itself has a Object t(instance variable/Field t) which is initialized in the Constructor of the main method Object t.
There's no unknown exception. A complete stack trace of the exception should be output.
instead of it dispaly null , 0 (nul for instance t(Object) and 0 for i)
Again, you are calling the Test constructor recursively. Take a look at that (ugly) diagram to see what's happening. You're creating new Test instances from the Test constructor. It will loop endlessly.
Exception in thread "main" java.lang.StackOverflowError at sun.nio.cs.SingleByteEncoder.encodeArrayLoop(Unknown Source)
.......... It's going on....
Joined: Aug 13, 2007
Christophe Verré wrote:What kind of exception ? StackOverflowError ? Which would not be surprising because you are recursively calling the Test constructor from the Test constructor. It's calling it again and again...
he is right then. You are call the constructor recursively that's why your program is throwing this exception.
remove t = new Test(); from constructor & your code will work without any error