If the base class and sub class implements the same interface and the method implementation of the abstract method is provided in the base class then do we have to provide the implementation in sub class also?
-
1why don't you try it yourself – pratikabu Jan 20 '18 at 06:12
4 Answers
Yes you can, and the implementation from subclass executes when you have initialisation paradigm
BaseClass v = new SubClass();
That's quite normal polymorphism/ovveriding.
Related : Can an interface extend multiple interfaces in Java?

- 120,458
- 37
- 198
- 307
-
-
If you try to make private, you see a compiler error Because you are reducing the visibility of the method. – Suresh Atta Jan 20 '18 at 05:38
do we have to provide the implementation in sub class also
No, you don't have to do it. If one class extends
another, it already has all (public
and protected
) methods declared in parent class.
But you can provide a different implementation of this method. In this case the method from the parent class will be overriden.

- 8,257
- 3
- 18
- 42
There is no need of implementing the same interface in both parent and child classes as because if you are implementing it in parent class then child will also have the same method but if you want to override you can override it.
public interface Shape {
void draw();
}
class Parallelogram implements Shape {
public void draw() {
System.out.println("This is Parallelogram");
}
}
public class Square extends Parallelogram {
@Override
public void draw() {
System.out.println("This Parallelogram is Square");
}
public static void main(String args[0]) {
Square square = new Square();
square.draw();
}
}
//Output This Parallelogram is Square
public class Rhombus extends Parallelogram {
public static void main(String args[0]) {
Rhombus rhombus = new Rhombus();
rhombus.draw();
}
}
//Output This is Parallelogram

- 204
- 1
- 8
- 26

- 227
- 3
- 15
It should not be required as subclass already has the method implementation in base class

- 2,571
- 1
- 11
- 27
-
What if the subclass have a different implementation for the same ? – Suresh Atta Jan 20 '18 at 05:33
-