Can one class extend multiple classes

Can one class extend multiple classes

Answer: No.It is the bad experience from C++ where this is possible but Java does not allow to do this.

The another approach for multiple inheritance is that a class can implement multiple interfaces (or an Interface can extend multiple Interfaces)

Actual confusion starts when interface define same methods and extends multiple interfaces.
Not only interfaces, A single class can also implements multiple interface. Then obviously a doubt raises, what if two methods have an same method name.

public interface InterfaceA {
	void test();
}
public interface InterfaceB {
	void test();
}
public interface InterfaceC extends InterfaceA,InterfaceB{

}

 

Using class:

package com.javahonk.multipleextends;

public class ABC implements InterfaceA, InterfaceB{

	public static void main(String[] args) {
		// TODO Auto-generated method stub

	}

	@Override
	public void test() {
		// TODO Auto-generated method stub

	}	

}

 

Noticeable thing is: Single implementation works for both.

Leave a Reply

Your email address will not be published. Required fields are marked *