c# - Creating a child object using a parent object -


let have these classes:

class {}; class b : {} ; 

and function return a:

 public read_an_a(); 

since b child of a, i'd able read it's a properties in following sense:

b b = new b ( read_an_a() ); 

(that assuming use of default copy constructor)

or maybe this:

b b = (b) read_an_a (); 

all of above broken, right way achieve that?

one way of doing add constructor of b takes a, , harvests relevant parts it:

public b(a a) {     this.x = a.x;     this.y = a.y; } 

your b class in best position know take, approach reasonably clean, too. lets write

b b = new b(read_an_a()); 

like suggested in question. of course b need other constructors, too.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -