Androidberry logo Androidberry text logo
AndroidBerry Home
  • Learn Java
  • Java Programs
  • Interview Questions
  • Androidberry facebook
  • Androidberry twitter
  • Androidberry google plus

Java Tutorials


Basic Introduction

Decision Making

Looping

Classes and Objects

Java Class
Java Object
Java Object Array
Java Nesting of Classes
Java Methods
Java Method Overloading
Java Constructor
Java Constructor Overloading
Java This Keyword
Java Garbage Collection
Java Static Keyword
Java Arrays
Java String
Java StringBuffer
Java String vs StringBuffer
Java Vector Class
Java Vector vs Array
Java Wrapper Classes

Inheritance

Java Inheritance
Java Single Inheritance
Java Super Keyword
Java Multiple Inheritance
Java Hierarchical Inheritance
Java Multilevel Inheritance
Java Method Overriding
Java Abstract Classes,Methods
Java Final Variables, Methods
Java Dynamic Dispatch Methods
Java Visibility Controls

Interfaces

Java Interface
Java Class vs Interface
Java Multiple Inheritance
Java Nested Interface

Packages

Java Packages
Java Built in packages
Java Package Access Specifiers

Exception Handling

Multithreading

Java Applets

Graphics Programming

More on Java

Java Programs
Java Keywords Dictionary
Java Interview Questions

Java Multiple Inheritance - using interface


Multiple Inheritance

In multiple inheritance there are multiple base classes accessed by a single derived class.

Java doens't support the concept of multiple inheritance by extending multiple classes. It is required in most of the real time applications hence it is possible by using interfaces.

Problems while extending multiple classes

  • In ealier programming languages like C++ there was a problem of ambiguity due to the multiple paths. Java totally removed this ambiguity problem in the Multiple inheritance
  • Ex- Consider there are 2 base classes having same method called display(). The third while calling the display method will confuse to call either from 1st base class or from 2nd base class.
  • Thats why java prevents to extend multiple classes at time. In some user applications we need to use the multiple inheritance concept. Java allows us to do by using interfaces by implementing them into a class.

Using interfaces for Multiple Inheritance

Using interfaces we can implement more than one interface into the class.

Multiple Inheritance

Syntax

interface Base1
{
    // method declarations;
    // final field = value;    
}

interface Base2
{
    // method declarations;
    // final field = value;    
}

interface Base3
{
    // method declarations;
    // final field = value;    
}

class DerivedClass implements Base1,Base2,Base3
{
    // interface method implementations;
    // body of Derived class    
}

Example


<< Previous Next >>

See Also

All Java Programs
Java Keywords
Java Interview Questions

AndroidBerry Support

About us
Contact us
Suggest us
Questions?

Follow us

Androidberry FacebookFacebook
Androidberry TwitterTwitter
Androidberry GooglePlusGoogle+
Back to top
Androidberry Name Logo