Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Repeated class name
Message
De
29/11/2003 08:05:06
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivie
 
 
À
28/11/2003 21:25:28
Information générale
Forum:
Java
Catégorie:
Autre
Divers
Thread ID:
00854350
Message ID:
00854418
Vues:
14
I see. In this case (working with subclasses), the duplicate class name might not be completely superfluous, as it seems at the first glance.

I think I was also forgetting briefly that the example I posted is actually a shortcut for what can also be written in two separate statements:
Button b
...
b = new Button(...)
>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
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform