You are on page 1of 15

CHAPTER 8

INHERITANCE IN JAVA

Eng. Mohamed Abdi Nor


master of computer science and Engineering
at Daffodil International University, Dhaka Bangladesh
INHERITANCE IN JAVA

Inheritance in java is mechanism in which one object


acquires all the properties and behaviors of parent
object. inheritance in java can be best understood in
terms of parent and child relationship also known as
superclass(parent) and subclass(child) in java.
inheritance defines is relationship b/w a super class and
its subclass extends and implements keywords are used
to describe inheritance in java
IMPORTANT POINTS

• inheritance the class which is give data members and


method is known as base or super or parent class.
• the class which is taking the data members and
methods is known as sub or derived or child class.
• the data members and method of class are known as
features.
• the concept of inheritance is also known as re-
usability or extendable classes or sub classing or
derivation
INHERITANCE IN JAVA
Term Definition

Definition is process where one object acquires the properties of


another object

subclass class which inherits the properties of another object


is called subclass

superclass class whose properties are inherited by subclass is


called as superclass

keywords used extends and implements


EXAMPLE INHERITANCE
ADVANTAGE OF INHERITANCE

• If we develop any application using concept of


inheritance than Application have following
advantage.
• Application development time is less
• Application take less memory
• Application performance is enhance(improved)
• Redundancy(repetition) of the code is reduced
or minimized so that we get consistence results
and less storage cost
DIS ADVANTAGES OF INHERITANCE

• Un supported – java not support multiple


Inheritance as well as hybrid inheritance.
• undefined– interface, properties are only
declared and assigned but never defined.
• Re-factory – if method is deleted in the super
class then we will have to re-factory in case that
using method.
In heritance parent class and child class
having multiple name,list of the name are
below:

Parent class = Base class = Super class


Child class = Derived class = Sub Class
EXAMPLE OF INHERITANCE

public class parents {


int z;
public void add(int x, int y) {
z = x + y;
System.out.println("addition is " + z);}
public void sub(int x, int y) {
z = x - y;
System.out.println("subtraction is " + z);
}
EXAMPLE OF INHERITANCE

public class child extends parents {


public void multiply(int x, int y) {
z = x * y;
System.out.println("multiplication is " + z);
public static void main(String[] args) {
int x = 5, y = 3;
child ob = new child();
ob.add(x, y);
ob.sub(x, y);
ob.multiply(x, y);

You might also like