Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Repeated class name
Message
From
28/11/2003 21:25:28
 
 
To
28/11/2003 19:43:24
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
General information
Forum:
Java
Category:
Other
Miscellaneous
Thread ID:
00854350
Message ID:
00854362
Views:
23
Button b = new Button(...)

the first "Button" is the type of the variable "b".
So "b" has a type of "Button"

In VFP (VFP7 or 8)we would say "b as int" in this case the variable would have a type of int (I've never really used this feature).

this "Button b" is creating the "reference variable" and providing the type.

The "new Button()" is creating the object (from a class)

The "=" assign or links the object and the reference.

I'm new too. So to the best of my knowledge there is no other sytax that does this.

Now the tricky part (not sure I understand it completely). The type of the reference varible is not limited to the type "Button". This is due to polymorphism. The following is an example (I'm using my example because I can't think of anything that works with Button)

Animal b = new dog()
Animal c = new cat()

The type of the reference variable can be anything that is a class that was extended (dog and cat are subclasses). Therefore since dog and cat are animals it works. Why is this important? Well that's another question. So far what I have gathered is as follows: By declaring the variable "Animal" I can pass the object to anything that will accept a subclass of "Animal". So if I have a class like "Pet_owner" it will accept both "b" (the dog) and "c" (the cat) reference varibles.
Hope this helps....


John
John Fabiani
Woodland, CA
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform