Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > question on interface

Reply
Thread Tools

question on interface

 
 
syntax
Guest
Posts: n/a
 
      02-15-2004
hi, i have some basic question on interface....

question1
------------
it is called that interfaces are similar to classes.

so, as classes can produce objects by usuing "new" keywords, can
interfaces do the same thing?

or in other words, does interfaces produce "object like" things
similar to classes?


question2
-----------

suppose a class is "implementating" an interface....so the class is
defining the method which is declared in the interface.

i want to know what would be the possible return types of the
following

return type = ObjectOftheClass.MethodDeclaredIntheInterface()

what would be return type? will it be a object of the class? or will
it be a "object like" thing of the interface?(if it exists!)

thanks
 
Reply With Quote
 
 
 
 
Joona I Palaste
Guest
Posts: n/a
 
      02-15-2004
syntax <(E-Mail Removed)> scribbled the following:
> hi, i have some basic question on interface....


> question1
> ------------
> it is called that interfaces are similar to classes.


> so, as classes can produce objects by usuing "new" keywords, can
> interfaces do the same thing?


> or in other words, does interfaces produce "object like" things
> similar to classes?


Yes or no. You cannot directly instantiate interfaces with new, but
you can instantiate classes implementing them. In other words, if
you have:

public interface IFoo {}
public class Foo implements IFoo {}

then this is an error:
IFoo i = new IFoo();
but this is OK:
IFoo i = new Foo();

> question2
> -----------


> suppose a class is "implementating" an interface....so the class is
> defining the method which is declared in the interface.


> i want to know what would be the possible return types of the
> following
>
> return type = ObjectOftheClass.MethodDeclaredIntheInterface()


> what would be return type? will it be a object of the class? or will
> it be a "object like" thing of the interface?(if it exists!)


The return type will be whatever the interface defines it to be. That
the method is implemented in the class doesn't change that. Of course,
the actual returned *object* might have another class, but the type
is the same. (If it's a primitive, it'll be the same type, period.)

--
/-- Joona Palaste ((E-Mail Removed)) ------------- Finland --------\
\-- http://www.helsinki.fi/~palaste --------------------- rules! --------/
"And according to Occam's Toothbrush, we only need to optimise the most frequent
instructions."
- Teemu Kerola
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Going from higher security level interface to lower security interface- HELP!!! - AM Cisco 4 12-28-2004 09:52 PM
PCI interface or USB interface David Wireless Networking 4 09-16-2004 01:01 PM
allow ssh only on outside interface, but telnet on inside interface of router no-one Cisco 0 07-28-2004 04:17 PM
PIX: how to allow 1 host from outside interface to access another host on the inside interface? jonnah Cisco 1 04-21-2004 02:26 PM
static nat between phisical interface and virtual interface on same ethernet Andrea Cisco 0 04-19-2004 09:37 AM



Advertisments