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

Inheritance Example

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

Inheritance Example

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

Single Inheritance Example :

class Teacher {

void teach() {

[Link]("Teaching subjects");

class Students extends Teacher {

void listen() {

[Link]("Listening to teacher");

class CheckForInheritance {

public static void main(String args[]) {

Students s1 = new Students();

[Link]();

[Link]();

}
Multilevel Inheritance :

class Teacher {

void teach() {

[Link]("Teaching subject");

class Student extends Teacher {

void listen() {

[Link]("Listening");

class homeTution extends Student {

void explains() {

[Link]("Does homework");

class CheckForInheritance {

public static void main(String argu[]) {

homeTution h = new himeTution();

[Link]();

[Link]();

[Link]();

}
Hierarchical Inheritance :

class Teacher {

void teach() {

[Link]("Teaching subject");

class Student extends Teacher {

void listen() {

[Link]("Listening");

class Principal extends Teacher {

void evaluate() {

[Link]("Evaluating");

class CheckForInheritance {

public static void main(String argu[]) {

Principal p = new Principal();

[Link]();

[Link]();

// [Link](); will produce an error

You might also like