OCJP

Extending Multiple Interfaces In Java

In Java we can not extend more than one class, but One Interface can extend more than one interfaces. Whenever any Child Class implement the last interface then it must override methods or parent interfaces also.

package jdbcdemo1;

interface Producer{
	
	void produceFilm();
}

interface Actor{
	void acting();
}

interface ActorProducerFinancer extends Producer, Actor{
	void finance();
}


class PersonX implements ActorProducerFinancer{

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

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

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

As above example does not have main class or main method so it can not be run. We have interface Producer and Actor as parent interfaces. One another interface ActorProducerFinancer extends both of parent interfaces. Now if class PersonX implements interface ActorProducerFinancer then it must override all the methods from Parent interfaces as well as child interface

Leave a Reply

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


× How can I help you?