Sample final Q2

35 views
Skip to first unread message

cs 210

unread,
Apr 22, 2011, 8:17:40 PM4/22/11
to UBC CPSC 210
I'm wondering why the call to Component.repaint() was included in the
call graph as it seems to belong to the Component class and is not
part of the ...drawingEditor.* packages.

Paul Carter

unread,
Apr 23, 2011, 2:29:36 AM4/23/11
to ubc-cp...@googlegroups.com
I believe the question indicated that you should include calls to methods that are inherited from super types. The repaint() method is inherited by Drawing from Component.

Paul

Caroline

unread,
Apr 25, 2011, 3:17:08 PM4/25/11
to UBC CPSC 210
Is it OK to include the method that was called in the in Tool
interface before the one in the RectangleTool class?

On Apr 22, 11:29 pm, Paul Carter <pcar...@cs.ubc.ca> wrote:
> I believe the question indicated that you should include calls to methods that are inherited from super types.  The repaint() method is inherited by Drawing from Component.
>
> Paul
>

Paul Carter

unread,
Apr 25, 2011, 3:31:11 PM4/25/11
to ubc-cp...@googlegroups.com
The abstract method (mousePressedInDrawingArea) in the Tool interface isn't actually called, so this shouldn't be included in the call graph.

Paul

Caroline

unread,
Apr 25, 2011, 5:02:17 PM4/25/11
to UBC CPSC 210
Oh - I thought that interface methods are "called" and then the Java
runtime environment decides which subclass to go to depending on the
type. If it's not called then what is it?

Paul Carter

unread,
Apr 25, 2011, 7:26:02 PM4/25/11
to ubc-cp...@googlegroups.com
It's not called in the sense that there is no code in an abstract method to execute. In this particular case the code that is actually executed is the code in the RectangleTool class and so it is this method that appears in the call graph. Recall that the actual type of an object reference determines which method is called. In this case we are told that the actual type of 'activeTool' is RectangleTool and so

activeTool.mousePressedInDrawingArea(e);

calls the mousePressedInDrawingArea method of the RectangleTool class.

Paul

Reply all
Reply to author
Forward
0 new messages