Correct cleanup in Java reuse class

Source: Internet
Author: User

Tag:package   bsp    Note    sys   xtend    line   system   super   ext   

: object/e05_dataonly2.java/****************** Exercise 5 ****************** * Modify Exercise 4 So the values * of the Data in DataOnly is assigned to and * printed in main (). /package object;class shape{Shape (int i) {System.out.println ("S    HAPE structure! ");}     void Dispose () {System.out.println ("Shape dispose");        }}class Circle extends shape{circle (int i) {super (i);    System.out.println ("Drawing Circle");        } @Override void Dispose () {System.out.println ("erasing Circle");    Super.dispose ();        }}class Triangle extends shape{Triangle (int i) {super (i);    System.out.println ("Drawing Triangle");        } @Override void Dispose () {System.out.println ("erasing Triangle");    Super.dispose ();    }}class Line extends shape{private int start, end;        Line (int start, int end) {super (start);        This.start = start; This.end = end;       System.out.println ("Drawing line:" + start + "," + end);        } @Override void Dispose () {System.out.println ("Erasing line:" + start + "," + end);    Super.dispose ();    }}public class E05_dataonly2 extends shape{private Circle circle;    Private Triangle Triangle;    Private line[] lines = new Line[3];                                             Public e05_dataonly2 (int i) {super (i + 1);       Shape Construction!        Super (i + 1); for (int j = 0; J < Lines.length; J + +)//j=0:shape construction! Drawing line:0, 0;j=1:shape Structure!                        Drawing line:1, 1 lines[j] = new Line (J, J * j); J=2:shape Structure!                                   Drawing Line:2, 4 circle = new Circle (1);                               Shape constructs the! drawing Circle triangle = new triangle (1);                     Shape constructs the! drawing Triangle System.out.println ("Combined structure"); Combined structure} @OverRide void Dispose () {System.out.println ("Cdasystem Dispose ()");                                         Cdasystem Dispose () circle.dispose ();                                       Erasing triangle        Shape dispose triangle.dispose ();               Erasing Circle Shape dispose for (int i = lines.length-1; I >= 0; i--)                                   Erasing Line:2, 4 Shape dispose        lines[i].dispose ();                                                                  Erasing line:1, 1 Shape dispose        Erasing line:0, 0 Shape DISPOSE&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NB        Sp                                          Super.dispose ();        Shape Dispose} public static void Main (string[] args) {e05_dataonly2 x = new E05_dataonly2 (47);    try {        //...        }        finally {x.dispose ();        }}}/*output Shape Construction!        Shape Construction!        Drawing line:0, 0 Shape construction!        Drawing line:1, 1 Shape Construction!        Drawing Line:2, 4 Shape Construction!        Drawing Circle Shape Construction! Drawing Triangle Combined Structure Cdasystem Dispose () erasing Triangle Shape dispose Erasi Ng Circle Shape Dispose erasing line:2, 4 shape Dispose erasing line:1, 1 shape dispo Se erasing line:0, 0 shape dispose shape dispose *///:~

The above comment is the comparison between program output and program execution, it should be noted that the establishment and destruction of subclasses is accompanied by the establishment and destruction of the parent class.

Correct cleanup in Java reuse class

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.