- 论坛徽章:
- 0
|
小弟最近同时学java和c++,有点疑问请教大家!!
首先大家看两段程序(很基本,但是我有疑问):
#include <stdio.h>
#include <iostream.h>
class mytest{
public:
mytest()
{
printf("test\n");
}
};
void main()
{
mytest test1,*hi;hi=&test1;
// cout<<test1;错误使用
cout<<&test1;cout<<hi;
}
public class test1{
public static void main(String args[])
{
test1 test1=new test1();
System.out.println(test1);//问题,怎么样才能输出他的地址呢。还有,到底C++中的类定义
//与java中的有什么不同。类名的含义有什么不同????
}
test1()
{
System.out.println("test");
}
}
我的问题就是java中定义一个类变量后,这个类变量到底代表什么?相当于一个指针吗?c++中定义一个类变量后,不用new就可以生成一个类对象,这于java中的实现机制有什么不同,他又代表一个什么东西呢?也许问题很弱智,还是大家希望能给我一点意见! |
|