aspose file tools*
The moose likes Beginning Java and the fly likes What is object? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "What is object?" Watch "What is object?" New topic
Author

What is object?

Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
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
jason adam
Chicken Farmer ()
Ranch Hand

Joined: May 08, 2001
Posts: 1932
Classes and objects are not the same thing. You instantiate an object from a class (the class is the blueprint for creating the object, or the cookie-cutter, if you want to use the common analogy). The object's type is whatever the classname is.
A variable also has a type. However, you don't manipulate objects directly through the variables, the variable instead holds a reference value to an object. The neat thing is that the variable might be of a certain type, and the object that the variable references be of another. For example, a Superclass variable type that really holds a reference to a Subclass object.
Hope that helps a little
Jason
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9047
    
  10
Q.1 myBirth is object or variable or they are the same meaning?

myBirth is a variable pointing to an object of type MyDate.

Similar to C++, an object is created by
new MyDate();
and is assigned to the variable myBirth.

int day, month, year;
are also variables of type int.

Q.2 Mydate is an object or class type or they are the same meaning?

You don't have anything named Mydate.
MyDate is a class. A class defines a type. You create objects of MyDate type (using the keyword "new") and refer to them by reference variables like myBirth.

JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Andrew Parker
Ranch Hand

Joined: Nov 12, 2001
Posts: 178
Thanks for help.
Andrew
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: What is object?