简体   繁体   中英

UML Class Diagram with super in constructor

public class A{
    public A(int num){ num += 2;}
}

public class B Extends A{
    public B(int num){ super(num);}
}

public class C Extends B{
    public C(int num){ super(num);}
}

How would something like this look as a UML class diagram? normally if only one class inherited from another, then I would use generalization. How would I take this on? A sample diagram would be great.

  • In UML, you don't need to repeat the same constructor in the children. They have it from the parent by default. That needn't be the same in all languages, though. So, you have these children constructors in Java, but you needn't show them in UML. But you can do it, of course.
  • The body of A() is senseless. You are changing the input parameter, and this has no consequences. I think, you meant:

 public class A{
    int num;
    public A(int num){ 
        this.num = num+2;
    }
 }

Anyway, this change is invisible on the class diagram

在此处输入图片说明

A class can easily have even two children, not a problem, in any language. The same for several generation generalization. In UML you can even have two parents of a child. But only few languages support this. Java is not in their number.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM