> And i could
> change the name of the object if i wanted?
Normally one doesn't change the names of objects after they are created. There isn't usually any point. However,
Label theLable2 = new Label();
theLabel2 = theLabel;
will make theLabel2 control the same object that theLabel controls.
> Refering to the line below, is it correct that Label
> is a class and theLabel is an object?
Label is a class, yes. No, theLabel is NOT an object. It is a variable, which can contain a reference to an object of type Label. Do not confuse variables with objects.
> And i could change the name of the object if i wanted?
Objects do not have names. You can't change the name of a variable after declaring it. You could certainly write a program that is identical to what you have there, except that you named the variable "theDonald" instead of "theLabel".
> ok i'm a little confused now, label is a class but
> what is theLabel? Some tell me an object, others a
> variable.
Depends. Variables are declared inside methods. Otherwise, it might as well be an attribute. But it is not an object.
What it is: it's a reference named theLabel, of type JLabel. Regardless of what it's pointing at.
> Label theLabel = new Label("hello");
In this case, the reference "theLabel" is pointing at an instance of Label.
Just to point out the difference between the reference type and the actual type of the instance:
Object o = new JLabel(); // reference is of the instance's supertype
List a = new ArrayList(); // reference is of the type of the interface implemented by the instance
Jlabel label = null; // reference of type JLabel points to the null type
On this note: casting can change the type of the reference, narrowing or broadening a "view" onto the instance moving along the inheritance hierarchy. It does not change the type of the instance behind it!