efrecdcxcfxfr125002231fewdsdsfxcdfe25.pdf

NidhiKumari899659 76 views 15 slides Aug 09, 2024
Slide 1
Slide 1 of 15
Slide 1
1
Slide 2
2
Slide 3
3
Slide 4
4
Slide 5
5
Slide 6
6
Slide 7
7
Slide 8
8
Slide 9
9
Slide 10
10
Slide 11
11
Slide 12
12
Slide 13
13
Slide 14
14
Slide 15
15

About This Presentation

vfv4 tgtrcgegt gtgtgg thth grg


Slide Content

DEPARTMENT OF INFORMATION TECHNOLOGY
P r e s e n t e d B y : B a r u n K u m a r S i n g h
R o l l N o : ( 1 2 5 0 0 2 2 3 1 2 5 )
B . T E C H
I T ( B )
3 R D Y e a r
P r e s e n t e d t o :-
D r . S a n g e e t a S e n

In java inheritance is a mechanism which one object can get all the properties and
behaviours of a parent object. In inheritance there is a relationship between two
classes. That’s why it is-a relationship.
For example: Bike, car, bus this
are vehicle. That’s why the
child of vehicle are bike,
car, bus and vehicle is the
parent of this objects.

•The important of inheritance in java program
is code reusability. We can reuse the function
of parent class at child class.
•In java we use Extends keyword for
inheritance.
•Subclass and Superclass in inheritance.

class Parent
{
//code
}
class Child extends Parent
{
//code
}

class super {
Public void display()
{
System.out.println(“I am parent class”);
}
}
class sub extends super {
public static void main(String args[])
{
sub message = new sub()
message.display();
}
}

ØSingle inheritance.
ØMultiple inheritance.
ØMulti-level inheritance.
ØHierarchical inheritance.
ØHybrid inheritance.
Note: In java Multiple inheritance is not supported.

Single inheritance is the most easy type to understand. In single
inheritance a class extends another only one class. The child
class inherit only parents class. The subclass inherit the objects
of superclass.
Example: A cat is a animal.
So a cat only can inherit the
objects of animal class.

class message_super {
Public void display()
{
System.out.println(“I am from superclass”);
}
}
class message_sub extends message_super {
public static void main(String args[])
{
Message_sub message = new message_sub()
Message.display();
}
}

When a class extends a class, and that class extends another class and its
object then it call multilevel inheritance.
Example: a class A is parent class.
Class B is inherit the
objects of class A. Another
one class c is child of class B.
class c can inherit the objects
of class C.

class a {
int data= 15; }
class b extends a {
}
class c extends b {
public void display() {
System.out.println(“number is:”+data);
}
public static void main(String args[])
{
c num= new c()
num.display();
}
}

When one superclass can be inherited by more than one subclass then it is
called hierarchical inheritance.
Example: a class A is parent class.
Class B is inherit the
objects of class A. Another
one class c also can inherit the
objects of class A.

Class Food
{
//code
}
class Rice extends Food{
//code
}
class Fruit extends Food{
//code
}

When a method is already in parent class but also declaring in child class, then
it is known as Method Overriding.
Note: But when it is ‘Final’ method it cannot overriding.
Example: A parent class of animal
has method ‘eat’. Also a child class
tiger has method ‘eat’.

class animal {
public void display() {
System.out.println(“I am animal”); }
}
class tiger extends animal {
public void display() {
System.out.println(“I am tiger”);
}
public static void main(String args[]) {
tiger t = new tiger();
t.display(); }
}
Tags