This site javatpoint is very useful for programming languages like JAVA,PYTHON,C,C++, Data Structures etc.Java learning Concept also provides technical materials , which are related to latest technologies. We provides very easy lectures to our viewers from beginning to advance level.We focus logical content instead of theoretical content.

Friday, 27 October 2017

MULTIPLE INHERITANCE IN JAVA

MULTIPLE INHERITANCE IN JAVA

Multiple inheritance is defined as two or more base classes being inherited by a single subclass. In Java this can't be done for the reason that it may lead to ambiguous results.  This mean that if two base classes contain the same method name and signature but the definition is different, then when the subclass inherits two or more base classes, there may be a conflict regarding which base class method is invoked. This type of inheritance is not achieved directly in Java.  Instead,  this can be achieved by interface in three ways
  • A class implements multiple interface 
  • An interface extends multiple interfaces
  • A class extends another class and implements an interface 

Syntax

Interface  A
{



}

Interface B

{



}


Class c implements A, B
{



}

Example 


interface joke
{
void m1();
}
interface poke
{
void m2();
}
class Sample implements joke,poke
{
public void m1()
{
System.out.println("hello java learning point");
}
public void m2()
{
System.out.println("wake up");
}
}
class Demo
{
public static void main(String args[])
{
rrr ob=new Sample();
ob.m1();
ob.m2();
}
}
Adbox