aspose file tools
The moose likes Java in General and the fly likes Copying parent class object into new subclass object Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Copying parent class object into new subclass object" Watch "Copying parent class object into new subclass object" New topic
Author

Copying parent class object into new subclass object

Wally Hartshorn
Ranch Hand

Joined: Jan 30, 2003
Posts: 77
Suppose I have a class (Dog), a subclass (Poodle), and a Dog object that I want to use to create a Poodle object.

One way to do that would be something like this:


Having to explicitly list all of the fields of the Dog object to set them in the Poodle object feels wrong. Is there a better way to do this?


Wally Hartshorn
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32708
    
    4
That shouldn't work if all the fields are correctly labelled private. If there is going to be that sort of copy constructor, it ought to be in the Dog classYou can have other constructors if you wish. You would have to check the design: do you really want a Poodle identical to another Dog in all respects except curliness?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Copying parent class object into new subclass object
 
Similar Threads
Generics extends keyword and getElement()
Why invalid syntax?
refrence casting....
question from khalid's book
casting