wood burning stoves 2.0
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 agree. Here's the link: http://aspose.com/file-tools
subject: Constructors
jQuery in Action, 3rd edition