0% found this document useful (0 votes)
11 views3 pages

Inheritance Java

The document explains the concept of inheritance in programming, detailing its types: single, multilevel, hierarchical, multiple, and hybrid inheritance. It provides code examples for single, multilevel, and hierarchical inheritance, demonstrating how classes can extend one another and share methods. Each example illustrates the relationship between parent and child classes and their respective functionalities.

Uploaded by

duraimullai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views3 pages

Inheritance Java

The document explains the concept of inheritance in programming, detailing its types: single, multilevel, hierarchical, multiple, and hybrid inheritance. It provides code examples for single, multilevel, and hierarchical inheritance, demonstrating how classes can extend one another and share methods. Each example illustrates the relationship between parent and child classes and their respective functionalities.

Uploaded by

duraimullai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

inheritance

**************

two or more classes connected is called inheritance

types
1.single inheritance
2.multilevel inheritance
3. hierarchical inheritance

====================
4. multiple inheritance
5.hybrid inheritance

======================
single inheritance
**********************

parent
|
child

class physics
{
public void psg()
{
System.out.println("Welcome to psg");
}
}

class college extends physics


{
public void department()
{
System.out.println("Welcome to d block");
}
}
class phy
{
public static void main (String arg[])
{
college j=new college();
j.department();
j.psg();
}
}

========================

multilevel

parent
|
child1
|
child2
====================

class chemsitry
{
public void lab()
{
System.out.println("Welcome to the lab");
}
}

class physics extends chemsitry


{
public void psg()
{
System.out.println("Welcome to psg");
}
}

class college extends physics


{
public void department()
{
System.out.println("Welcome to d block");
}
}

class phy
{
public static void main (String arg[])
{
college j=new college();
j.department();
j.psg();
j.lab();
}
}

=======================

3.hierarchichal

-------parent ----
| |
child 1 child2

========================

class chemsitry
{
public void lab()
{
System.out.println("Welcome to the lab");
}
}

class physics extends chemsitry


{
public void psg()
{
System.out.println("Welcome to psg");
}
}

class college extends chemsitry


{
public void department()
{
System.out.println("Welcome to d block");
}
}

class phy
{
public static void main (String arg[])
{
college j=new college();
j.department();
j.lab();
physics k=new physics();
k.psg();
k.lab();
}
}

======================

You might also like