You are on page 1of 2

Assignment #4

Task 1

Multiple inheritance is not supported by classes in Java. However, it is supported by


interfaces. An interface is a blueprint of a class that provides a set of abstract methods
that a class must implement. Multiple inheritance by interface occurs if a class
implements multiple interfaces or also if an interface itself extends multiple interfaces.

Here is an example of a class that implements two interface

public class MyClass implements Printable, Drawable {

@Override

public void print() {

System.out.println("This is a printable object.");

@Override

public void draw() {

System.out.println("This is a drawable object.");

public class MyClassDemo {

public static void main(String[] args) {


// Create a MyClass object

MyClass myObject = new MyClass();

// Print the MyClass object

myObject.print();

// Draw the MyClass object

myObject.draw();

You might also like