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 Inheritance


Inheritance

Inheritance is the method of deriving a new class from existing one.The main idea behind the using inheritance is the re usability of code instead of writting again and again.

The existing or old class which is reused called as base class or parent class or superclass. The new class which is going to use that class called as Derived class or child class.

The new class can have its own properties and well as parent properties.

Types of Inheritance

  1. Single Inheritance
  2. Multiple Inheritance
  3. HierarchicalInheritance
  4. Multilevel Inheritance
  5. Hybrid Inheritance
Note : Java doesn't support the Multiple and Hybrid Inheritance. Which can achieve this by using interface concept, we see later on.

1.Single Inheritance

Single Inheritance

In Single Inheritance, There are two classes in which one base class and another is derived class. The derived class accesses all the properties of base class based on the visibility specifier.

In fig. Class A is the base class and Class B is the derived class. The arrow always points towards the Derived classes.

extends keyword is used for accessing the properties of class.


2.Multiple Inheritance

Multiple Inheritance

In Multiple Inheritance, There are multiple base classes which are accesses by only single derived class.

In fig. Class A and Class B are the two base classes which are derived into derived class C

While accessing the properties of base classes all the properties of base classes are copied into base class based on their their visibility


3.Hierarchical Inheritance

Hierarchical Inheritance

In Hierarchical inheritance, There is only one base class but multiple Derived Classes

In fig. Class A is only one base class and Class B,C,D are the three derived classes.

Multiple base classes accesses the properties of single base class. But the base decides which kind of data should be given for others and which not.


4.Multilevel Inheritance

Multilevel Inheritance

In Multilevel inheritance There is a base class which is extended into derived class. Then again derived class acts as a base class for next derived class.

In fig. Class A is base class which is accessed by Derived class B, Again class B is accessed by Class C. But class B acts as base class for class C.


5.Hybrid Inheritance

Multilevel Inheritance

Hybrid Inheritance is a combination of Single and Multiple Inheritance or we can say Hybrid Inheritance is a Combination of more than one type of Inheritance.

There could be situations where we need to apply two or more types of inheritance to achieve some need in the program.That moment hybrid inheritance is very much important

In fig. Class A,B,C are together called as Multilevel Inheritance and Class D,E are called as SIngle Inheritance.


<< 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