I need to convert this program to java. I can handle everything else but the destructor. Now I've already read all over about the GC(garbage collector) and it unreliability. I am thinking why put a destructor for me to convert anyways if there wasn't a way or something.
#include<iostream>
using namespace std;
class Timer{
public:
Timer();
~Timer();
};
Timer::Timer(){
cout<<"Install a timer"<<endl;
}
Timer::~Timer(){
cout<<"Demolition of timer"<<endl;
}
class Bomb: public Timer{
public:
Bomb();
~Bomb();
};
Bomb::Bomb(){
cout<<"Install a timer in bomb"<<endl;
}
Bomb::~Bomb(){
cout<<"Bomb explode..."<<endl;
}
int main()
{
Timer* aTimer = new Timer;
Bomb* aBomb = new Bomb;
delete aTimer;
delete aBomb;
system("pause");
return 0;
}
So far, what I came up with was this stuff using Eclipse...
public class mainting{
public static void main(String test[])
{
timer atimer = new timer();
bomb abomb = new bomb();
}
}
public class bomb extends timer {
public bomb(){
System.out.println("Install a timer in bomb");
}
}
public class timer {
public timer()
{System.out.println("Install a timer");}
}
pretty straight forward I know.
This is the output of the code in C++
Install a timer
Install a timer
Install a timer in bomb
Demolition of timer
Bomb exploded
Demolition of timer