Code Comments
Programming Forum and web based access to our favorite programming groups.zcraven wrote:
> if (p2,p3,p4==Goalkeeper)
> {
> throw new IllegalArgumentException("You cannot put a goalkeepe
r
> in an outfield position");
> }
>
>
> I want to check that the variables p2 to p11 are of class OutfieldPlayer a
nd
> not Goalkeeper (Both OutfieldPlayer and Goalkeeper are subtypes of abstrac
t
> class Player). How do I write an if to check that the variables are of a
> certain class?
You should probably have a moveTo() method in Player
and override it as appropriate so
newplayer.moveTo(OUTFIELD)
would throw an exception if newplayer is an instance of Goalkeeper.
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.