vineri, 4 septembrie 2015
Java: Dispose Sample
public class ShapesSample extends Shape {
Cicle c;
Square s;
public ShapesSample(int i) {
super(i);
c = new Cicle(i);
s = new Square(i);
System.out.println("ShapesSample ctor");
}
@Override
void dispose() {
s.dispose();
c.dispose();
System.out.println("ShapesSample dispose");
super.dispose();
}
public static void main(String[] args) {
ShapesSample sample = new ShapesSample(0);
try {
}
finally {
sample.dispose();
}
}
}
class Shape {
Shape(int i) {
System.out.println("Shape ctor");
}
void dispose() {
System.out.println("Shape dispose");
}
}
class Cicle extends Shape {
Cicle(int i) {
super(i);
System.out.println("Cicle ctor");
}
@Override
void dispose() {
System.out.println("Cicle dispose");
super.dispose();
}
}
class Square extends Shape {
Square(int i) {
super(i);
System.out.println("Square ctor");
}
@Override
void dispose() {
System.out.println("Square dispose");
super.dispose();
}
}
Abonați-vă la:
Postare comentarii (Atom)
Niciun comentariu:
Trimiteți un comentariu