same old question: interface Vs. Abstract class
- From: "zeroone" <mail2sharma@xxxxxxxxx>
- Date: 7 May 2005 05:58:49 -0700
Hi all,
I m a C++ programmer basically & recently got into JAVA tech.
I have 2 doubts:
-----------------
FIRST :
-----------------
Interface keyword adv: Multiple inheritance like C++. but avoid all
ambguity dirt of MI.
ABC adv: base code can be given to child class.
Suppose I m damn sure that my kid concrete class objects will have
different behaviour for same request issued and all methods will be
clubed within one dady ABC. Then I think I should use ABC only over
interface for speed optimization.
Here is some sample code that I thought will help u guys understand me
better.
X can be considered as the Factory class.
//BEGIN.
[root@MaujDev documents]# cat C.java
abstract class Character{
abstract public void method();
}
class B extends Character{
public void method() {System.out.println("This is B class");};
}
class X{
public static Character newCharacter(){
return new B();
}
}
class C
{
public static void main(String args[]){
Character x = X.newCharacter();
x.method();
}
};
[root@MaujDev documents]# cat J.java
interface Character{
public void method();
}
class B implements Character{
public void method() {System.out.println("This is B class");};
}
class X{
public static Character newCharacter(){
return new B();
}
}
class D
{
public static void main(String args[]){
Character x = X.newCharacter();
x.method();
}
};
[root@MaujDev documents]#
//END.
-----------
SECOND
-----------
I read this line some where on internet.
/*************
A bird can fly(). So can a aircraft, but aircraft inheriting from bird
doesnt make sense. I fully agree.
**************/
But What if it can be phrased as:
Bird inherit from FlyingThing() and LivingThing().
Aircraft inherit from FlyingThing() and NonLivingThing().
but both FlyingThing() and LivingThing() will inherit from Thing()
which will provide all the base code to register as a valid object in
this world.
In C++ its MI provided programmers dont do stupidty.
How will one phrase the same in JAVA. Its obvious I define interfaces
in C++. I write ABC with all the stuff virtual.
.
- Follow-Ups:
- Re: same old question: interface Vs. Abstract class
- From: iamfractal
- Re: same old question: interface Vs. Abstract class
- From: Hal Rosser
- Re: same old question: interface Vs. Abstract class
- Prev by Date: Re: Making sure a class has a certain method
- Next by Date: Re: Making sure a class has a certain method
- Previous by thread: Re: Java StreamTokenizer
- Next by thread: Re: same old question: interface Vs. Abstract class
- Index(es):
Relevant Pages
|