Author Topic:   super classes and interfaces
priyavardheesh
greenhorn
posted May 01, 2000 02:28 PM             
hi everybody,

abstract class Super
{
abstract void shape();
}

interface Design
{
void shape();
}

class Sub extends Super implements Design
{
//which shape() needs to be given implementation
}

getting

edward man
unregistered
posted May 01, 2000 06:56 PM           
Here is my version:


abstract class Super
{
abstract void shape();
}

interface Design
{
void shape();
}

class Subclass extends Super implements Design
{
//which shape() needs to be given implementation
public void shape ()
{
System.out.println ("I am the overrided shape");
}

public static void main (String args [])
{
Super shape1 = new Subclass ();
shape1.shape ();
Design shape2 = new Subclass ();
shape2.shape ();
}
}

It doesn't matter what shape() it is as long as both of them having the same signature in Super and Design. When you implement the shape () method in a subclass you are actually overriding the one in both Super and Design.

One thing to watch is all methods declared in an interface are implicitly declare public. That's why I have to declare "public void shape ()" in the subclass. Without the public modifier, the java compiler will complain.

Tony Alicea
sheriff
posted May 01, 2000 07:16 PM             
That one

I don't have time to test (I already passed Certification) but I'm sure you have the time if you're still studying

From what I remember reading is that since both methods have the same signature, one implementation will satisfy both at the same time... Your mileage may vary...

maha anna
bartender
posted May 01, 2000 07:57 PM             
If the return type of the 2 methods with the same name would have been different, then the compiler is confused and yells at us. . Because it does not know which method, the subclass could possibly implement. You can't have 2 methods with same signature and different return types in the same class right?

regds
maha anna

[This message has been edited by maha anna (edited May 01, 2000).]

|