[4073] in java-interest

home help back first fref pref prev next nref lref last post

Re: [Q] getWidth(this), why passing 'this'?

daemon@ATHENA.MIT.EDU (Gary Aitken)
Sat Dec 9 04:02:00 1995

Date: Sat, 9 Dec 1995 00:28:28 -0700
From: garya@village.org (Gary Aitken)
To: Edith Au <edith@pencom.com>, java-interest@java.sun.com
In-Reply-To: <9512081655.aa29746@china.pencom.com>



>public class a extends Applet
>{
>	Image im;
>
>	public void init()
>	{
>		try 
>		{
>			im = getImage(/* an image */);
>		}
>		catch (Exception e) 
>		{}
>		
>		imWidth = im.getWidth(this);
>	}
>}
>
>  According to the API, getWidth takes an ImageObserver object as a parameter.
>'this' is an applet.  The only common ancestor of Applet and imageObserver is
>Object.  How come 'this' can be passed as an mageObserver?

Applet is derived (indirectly) from Component, and Component implements
ImageObserver.  One of the characteristics of interfaces is that if a
class implements an interface, you may pass an object of the class as
an argument of the interface type.  Effectively, only the subpart of the 
class object which deals with implementing the interface is passed.

Gary Aitken		garya@village.org
-
This message was sent to the java-interest mailing list
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post