Hi,
I have learnt C/C++ before and know how to create an object.
When I read the student guide of the java lang, e.g.
class MyDate {
int day, month, year;
}
MyDate myBirth = new MyDate();
This statement allocates the space for the 3 integers used to form MyDate. Object assignment sets up the variable myBirth to refer to the new object. The contents of the MyDate object can be accessed through myBirth.
Q.1 myBirth is object or variable or they are the same meaning?
Q.2 Mydate is an object or class type or they are the same meaning?
In C++, it is clear that, for instance,
class MyDate {
int a, b, c;
};
main() {
MyDate myBirth; //An object is created.
}
or main() {
MyDate* pmyBirth = new MyDate; //An object is created dynamically.
delete pmyBirth;
}
I am confused with the terminology, MyDate is class in C++. But, MyDate is also an object in Java.
Anyone could clarify it for me?
Thanks
Andrew
I have learnt C/C++ before and know how to create an object.
When I read the student guide of the java lang, e.g.
class MyDate {
int day, month, year;
}
MyDate myBirth = new MyDate();
This statement allocates the space for the 3 integers used to form MyDate. Object assignment sets up the variable myBirth to refer to the new object. The contents of the MyDate object can be accessed through myBirth.
Q.1 myBirth is object or variable or they are the same meaning?
Q.2 Mydate is an object or class type or they are the same meaning?
In C++, it is clear that, for instance,
class MyDate {
int a, b, c;
};
main() {
MyDate myBirth; //An object is created.
}
or main() {
MyDate* pmyBirth = new MyDate; //An object is created dynamically.
delete pmyBirth;
}
I am confused with the terminology, MyDate is class in C++. But, MyDate is also an object in Java.
Anyone could clarify it for me?
Thanks
Andrew