0
0
Javaprogramming~10 mins

Multiple inheritance using interfaces in Java - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to declare an interface named Printable.

Java
public interface [1] {
    void print();
}
Drag options to blanks, or click blank then click option'
APrint
BPrintable
CPrinter
DPrintInterface
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a class name instead of interface name.
Misspelling the interface name.
2fill in blank
medium

Complete the code to declare a class Document that implements Printable interface.

Java
public class Document implements [1] {
    public void print() {
        System.out.println("Printing document");
    }
}
Drag options to blanks, or click blank then click option'
APrintable
BPrinter
CPrint
DPrintableInterface
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a class name instead of interface name in implements.
Misspelling the interface name.
3fill in blank
hard

Fix the error in the class declaration to implement two interfaces: Printable and Showable.

Java
public class Report implements [1] {
    public void print() {
        System.out.println("Printing report");
    }
    public void show() {
        System.out.println("Showing report");
    }
}
Drag options to blanks, or click blank then click option'
APrintable, Showable
BPrintable & Showable
CPrintable Showable
DPrintable | Showable
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using & or | instead of commas.
Omitting commas between interface names.
4fill in blank
hard

Fill both blanks to complete the interface declarations and class implementing both.

Java
interface [1] {
    void print();
}
interface [2] {
    void show();
}
class Presentation implements Printable, Showable {
    public void print() {
        System.out.println("Print slide");
    }
    public void show() {
        System.out.println("Show slide");
    }
}
Drag options to blanks, or click blank then click option'
APrintable
BPrintableInterface
CShowable
DShowInterface
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Mismatch between interface names and class implements clause.
Using different names for interfaces.
5fill in blank
hard

Fill all three blanks to complete the code that uses multiple inheritance with interfaces and calls their methods.

Java
interface [1] {
    void print();
}
interface [2] {
    void show();
}
class Report implements Printable, Showable {
    public void print() {
        System.out.println("Printing report");
    }
    public void show() {
        System.out.println("Showing report");
    }
}
public class Main {
    public static void main(String[] args) {
        [3] obj = new Report();
        obj.print();
        obj.show();
    }
}
Drag options to blanks, or click blank then click option'
APrintable
BShowable
CReport
DPrintableShowable
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a non-existent interface name for the variable type.
Using interface names instead of class name for the object.