File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Abstract Class and Constructor doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Abstract Class and Constructor doubt" Watch "Abstract Class and Constructor doubt" New topic
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
    
    4
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
 
jQuery in Action, 2nd edition
 
subject: Abstract Class and Constructor doubt
 
Similar Threads
anybody give me link to good source to read i/o streams
String Problem.
about abstract method and class
Abstract classes - instantiation
Can non abstract methods can access abstract methods