The Artima Developer Community
Sponsored Link

Java Answers Forum
interface reference assignment

1 reply on 1 page. Most recent reply: Sep 24, 2003 9:04 PM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Guido

Posts: 38
Nickname: kiethb
Registered: May, 2002

interface reference assignment Posted: Sep 24, 2003 11:23 AM
Reply to this message Reply
Advertisement
I am going through the Smart Certify training course. I do not understand one of the things on reference assignment.

It says in the form of a chart, that you can assign an interface to a class as long as that class is of type Object.

Since you can not instantiate an interface what is the sense in this? I did the following:

interface1 inter1 = null; //null because i could not init anyway else.
Object obj1 = inter1;

this compiled fine, but does not tell me what I need to know. first of all, how can I assign a reference of an actual interface to a class reference? Also, WHY would I want to do that?

thank you for your help


mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: interface reference assignment Posted: Sep 24, 2003 9:04 PM
Reply to this message Reply
java.awt.event.MouseListener

is an interface.

You can say it like

no say if u have class such as

MouseCatDogCatcher extends MouseAdapter
{
}
Then say as ...
As MouseAdapter implements interface.

MouseListener mouseCatDog = new MouseCatDogCatcher();

Why interface???
first know what is interface??
http://java.sun.com/docs/books/tutorial/java/interpack/interfaceDef.html

Flat View: This topic has 1 reply on 1 page
Topic: Applet won't run!!! Need help! Previous Topic   Next Topic Topic: Format a number as Date

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use