| Author |
Abstract Class and Constructor doubt
|
Yogendra Joshi
Ranch Hand
Joined: Apr 04, 2006
Posts: 206
|
|
Hello All,
Today i was interviewed and didnt get selected, however i took this interview as a learning curve for myself. One of the tricker question being asked to me at the interview was "In an abstract class, do you have a constructor ? If yes, since we cannot instantiate Abstract class, wont that code be unreachable?"
I got confused at that question and when i came home and researched, I came to know that Every class including abstract class does have a constructor and its called when the Object of its implementation class is created. So for testing this out, I wrote a small code to verify my understanding.
Here's what i coded :
YNJAbstract.java
Implementation Class : YNJTest.java
Understand was correct, however my code landed in a problem and here's the output...
Yogendra
Yogendra
Yogendra
.
.
.
Exception in thread "main" java.lang.StackOverflowError
Can someone please explain me what wrong i did in this code?
Thanks in advance,
Yogendra N Joshi
|
Meri Zindagi Hain Tab Tak.. Jab Tak Tera Sahara.... Har Taraf Tu Hi Tu Hain SAI Tera Hi Hain Nazara.....
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32599
|
|
|
You have somehow created an endless recursion, hence the Stack Overflow. It is not obvious how; the code you have posted doesn't appear to be the code you are running.
|
 |
Muhammad Khojaye
Ranch Hand
Joined: Apr 12, 2009
Posts: 341
|
|
|
http://stackoverflow.com/questions/260666/abstract-class-constructor-in-java
|
http://muhammadkhojaye.blogspot.com/
|
 |
Yogendra Joshi
Ranch Hand
Joined: Apr 04, 2006
Posts: 206
|
|
Hi,
Thanks for the help. Actually the class name should have been YNJTest while invoking and i somehow mistakenely gave abc while making new.
Its resolved now. This can be closed.
Thanks a lot.
Yogendra
|
 |
 |
|
|
subject: Abstract Class and Constructor doubt
|
|
|