
Line
package Association;
public class Line {
private int length;
public Line(int length) {
this.length = length;
}
public void display() {
System.out.println("Lenght:" + length);
}
}
Circle
package Association;
public class Circle {
private double radius;
public Circle(double radius) {
this.radius = radius;
}
public void display() {
System.out.println("radius:" + radius);
}
}
Rectangle
package Association;
public class Rectangle {
private int height, width;
Circle c;
Line l;
public Rectangle(int height, int width, Circle c, Line l) {
this.height = height;
this.width = width;
this.c = c;
this.l = l;
}
public void display() {
System.out.println("\n" + "Height:" + height + "\nWidth:" + width);
c.display();
l.display();
}
public static void main(String[] args) {
Circle c1 = new Circle(12.0);
Line l1 = new Line(20);
Rectangle r1 = new Rectangle(10, 20, c1, l1);
r1.display();
Rectangle r2 = new Rectangle(13, 50, c1, l1);
r2.display();
}
}
Output

- CGPA Converter with JSwing
- UML[ 03 ] Code with Abstract and Interface
- UML[ 02 ] Code with Abstract and Interface
- UML[ 01 ] Code with Abstract and Interface
- Do you know “What is Loop in Java ?”