Show Mobile Navigation

Webring

Powered by WebRing.

What is inheritance and how to use inheritance in Java

Sachin R Kukale - 02:08
Inheritance is important OOPs property by which you can inherit some or all the features of one member to another member. In java inheritance is applied using classes and interfaces. Inheritance provides us facility of reusability and we can avoid code duplication problem using inheritance.
In Java inheritance relationship is defined using the keyword ‘extends’ with classes and inheritance between interfaces is defined using the keyword ‘implements’.
A class can inherit the interfaces but a interface can not inherit the features of class.
Inheritance is a kind of ‘is a relationship’.
When you declare a reference type in a class then it is ‘has a relationship’.
Ex: Simple inheritance:
class users{
//Statement(s).
}
class Students extends Users{
//Statement(s).
}
Ex: Multilevel inheritance:
class A{
......
}
class B extends A {
.......
}
class C extends B{
...........
}
Ex: Multiple inheritance:
class A {...}
class B {...}
class C extends A,B{
.....

}

0 comments:

Post a Comment