Meaningless Drivel is fun!*
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes DBMain Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "DBMain" Watch "DBMain" New topic
Author

DBMain

Beny Na
Ranch Hand

Joined: May 26, 2004
Posts: 159
hi all,
my assignment is urlbird
Sun give me DBMain as an interface and Data as a class that implements DBMain.

in my Data.java, i have add some extra methods that are not defined in DBMain.

I need to use reference of type DBMain that call a method that is added in Data class. How to do that since we can't do that in java?
e.g
interface DBMain{
void methodA();
}

class Data implements DBMain{
void methodA(){}
void methodB{}{} // add a new method that is not defined in DBMaininterface
}

class Test{
.....
DBMain db = new Data();
/* how to call db.methodB() using reference of type DBMain */
....

pls help
thanks
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
How about???

class Test{
.....
Data db = new Data();
/* how to call db.methodB() using reference of type Data*/
....
}


SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
Or...you could extend the DBMain interface and have Data implement that:

Beny Na
Ranch Hand

Joined: May 26, 2004
Posts: 159
hi Simon, thanks for your reply,
anyway, it is sun requirement that Data.java "must" implement DBMain interface. If Data doesn;t implement the DBMain that is provided by sun then it could result in automatic failure..

thanks..
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
Hi Beny,

Ok...so you have Data implement DBMain.

Then implement all abstract methods (e.g. methodA) from DBMain in Data.

Add any other methods (e.g. methodB) to Data.

Then instantiate an object, say myData, as type Data (not DBMain) and then you can call myData.methodA() or myData.methodb().

Cheers,

Simon
Beny Na
Ranch Hand

Joined: May 26, 2004
Posts: 159
what i need to do is using reference of type interface DBMain and the actual object is Data.
eg. DBMain db = new Data();
db.methodB() // db doesnt' know anything about methodB() therfore this statement will not run, and how to make it works?

Except if i create another interface that has methodB() and another interface implements DBMain.
e.g interface XXX { methodB()}
interface YYY extends XXX,DBMain{}

public class Data implements DBMain,YYY{}

my main reference will be YYY that know methodA and methodB.
e.g YYY data = new Data();
data.methodB(); // it will work, but not the right answer..

My Data.java will implements DBMain and required to implements Observable as well, because i am trying to apply mvc pattern in my assignment, and reference of type DBMain will be required in my Controller constructor .

i hope you understand what i mean, sorry if my writing confuse you.


thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: DBMain
 
Similar Threads
Testing of data class instance(s)
Remote interface for Data class with RMI
[URLyBirdHotel 1.3.3] Can I add more interfaces on Data.java?
Using the unreferenced interface
About stop the RMI server