This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Java in General and the fly likes Constructors Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

JavaRanch » Java Forums » Java » Java in General
Bookmark "Constructors" Watch "Constructors" New topic


Manju KT

Joined: Jan 16, 2008
Posts: 7
Can anybody tell me whether we can create a instance of type subclass using superclass constructor?
Charmy Madhvani
Ranch Hand

Joined: Dec 26, 2007
Posts: 59
You mean to say:
Child c=new Parent();

No..This is not valid in Java.
You can only have a Parent type reference to a child type object but not vice versa.

SCJP 5.0<br />SCWCD 5.0
Ben Souther

Joined: Dec 11, 2004
Posts: 13410

"Manju KT",
Please check your private messages.

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Constructors
jQuery in Action, 3rd edition