DBMain
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
How about???
class Test{
.....
Data db = new Data();
/* how to call db.methodB() using reference of type Data*/
....
}
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
Posts: 214
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
Or...you could extend the DBMain interface and have Data implement that:
SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
Beny Na
Ranch Hand
Posts: 159
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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..
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
Posts: 214
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
Beny Na
Ranch Hand
Posts: 159
posted 19 years ago
-
-
Number of slices to send:Optional 'thank-you' note:
-
-
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
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
| Come have lunch with me Arthur. Adventure will follow. This tiny ad: The new gardening playing cards kickstarter is now live! https://www.kickstarter.com/projects/paulwheaton/garden-cards |









