Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I want to equalize two object like this:

    public abstract class Shape{...} // There is an abstract shape class

    public class Circle extends Shape {
        int radius;
        ...
    }

    public class ColoredCircle extends Circle{
        Color color;
        public ColoredClass(Circle circle) {
            this = circle;                  // This line has a problem. 
            this.color = Color.RED;
        }
    }

How can i copy all fields to sub-class with current values?

share|improve this question
2  
there is a difference between "inherit" and "copy". You should learn those basic programming skills with Pascal, not Java. There si also no "equalize" in programming. You must learn the concept of references/pointers and memory model. – Ivan Kuckir Apr 20 at 13:12
2  
This belongs on stackoverflow. – Byte56 Apr 20 at 15:30
So, how can i "copy" ? – karakale Apr 20 at 15:36
shallow or deep copy? – sarahm Apr 20 at 19:33
1  
Every language tutorial has a section of copying objects, plus coverage of shallow versus deep copies. Time to go get some readin' done, I think. Plus, this is not a game related question at all and really belongs on stack overflow or programming. – Patrick Hughes Apr 21 at 3:22
show 1 more comment

closed as off topic by Anko, Byte56, Josh Petrie, msell, Patrick Hughes Apr 21 at 3:22

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

1 Answer

Many classes will have either a "copy constructor" that accepts a source instance of the class as a single parameter, or a Copy() or Clone() method that returns a copy/clone of the instance.

However, to use any of these effectively you will need to learn the details of shallow and deep copying/cloning. Research the methods you use for this, and Google the web for references on this topic.

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.