我需要将此程序转换为java。除了析构函数外,我可以处理其他所有的东西。现在我已经阅读了关于GC(垃圾回收器)的所有内容,并且它不可靠。我在想,为什么把一个析构函数转换成无论如何,如果没有任何方式或东西。C++到Java转换 - 破坏者
#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;
}
到目前为止,我想出了使用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");}
}
非常简单的,我知道。
这是代码的在C++输出
Install a timer
Install a timer
Install a timer in bomb
Demolition of timer
Bomb exploded
Demolition of timer
Java不工作的方式。相反,使用试用资源。 – SLaks
你想要我们转换此代码?你为什么不尝试发布你所带的东西! – Infested
有时在语言翻译中没有直接翻译。 – andre