0% found this document useful (0 votes)
2 views4 pages

Java Hybrid and Multiple Inheritance Example

The document demonstrates hybrid inheritance in Java through classes and interfaces, showcasing how a class can inherit from another class and implement an interface. It also illustrates multiple inheritance using interfaces, where one interface extends others, and provides an example of implementing these interfaces in an anonymous class. The main method in both examples creates instances and calls methods to display results.

Uploaded by

satya
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)
2 views4 pages

Java Hybrid and Multiple Inheritance Example

The document demonstrates hybrid inheritance in Java through classes and interfaces, showcasing how a class can inherit from another class and implement an interface. It also illustrates multiple inheritance using interfaces, where one interface extends others, and provides an example of implementing these interfaces in an anonymous class. The main method in both examples creates instances and calls methods to display results.

Uploaded by

satya
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

Hybrid inheritance in java

class Student {

int no;

void getno(int n) {

no=n; }

void show() {

[Link](no); }}

class Test extends Student {

int p1, p2;

void getm(int m1, int m2) {

p1=m1;

p2=m2; }

void showm()

[Link](p1);

[Link](p2);

interface sports

int s=7;

void putw();

class Result extends Test implements Sports


{

int total;

public void putw()

[Link](s);

void display()

total=p1+p2+s;

show();

showm();

putw();

[Link](total);

class Hybrid

public static void main(String args[])

Result s1=new Result();

[Link](11);

[Link](37, 45);

[Link]();

}
Multiple inheritance in java

interface Event { // interface 1

public void start();

interface Sports { // interface 2

public void play();

// another interface extending 1st and 2nd interface

interface Hockey extends Sports, Event{

public void show();

public class Tester{

public static void main(String[] args){

// creating instance of hockey

Hockey hockey = new Hockey() {

// implementing the methods of interfaces

public void start() {

[Link]("Start Event");

public void play() {

[Link]("Play Sports");

public void show() {

[Link]("Show Hockey");

};
// calling the methods using instance

[Link]();

[Link]();

[Link]();

You might also like