0
0
Javaprogramming~10 mins

Implementing 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'
APrintInterface
BPrint
CPrinter
DPrintable
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using a class name instead of an interface name.
Misspelling the interface name.
2fill in blank
medium

Complete the code to make class Document implement the Printable interface.

Java
public class Document [1] Printable {
    public void print() {
        System.out.println("Printing document...");
    }
}
Drag options to blanks, or click blank then click option'
Ainherits
Bextends
Cimplements
Duses
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using extends instead of implements.
Forgetting to implement all interface methods.
3fill in blank
hard

Fix the error in the class by correctly overriding the print method from the Printable interface.

Java
public class Report implements Printable {
    public void [1]() {
        System.out.println("Report printing...");
    }
}
Drag options to blanks, or click blank then click option'
Aprint
BPrint
Cdisplay
Dshow
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using uppercase 'P' in method name.
Using a different method name than declared in the interface.
4fill in blank
hard

Fill both blanks to declare an interface and a class that implements it.

Java
public interface [1] {
    void display();
}

public class Screen [2] Displayable {
    public void display() {
        System.out.println("Displaying screen...");
    }
}
Drag options to blanks, or click blank then click option'
ADisplayable
Bextends
Cimplements
DDisplay
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using extends instead of implements for interfaces.
Mismatching interface names.
5fill in blank
hard

Fill all three blanks to create an interface, implement it in a class, and override the method.

Java
public interface [1] {
    String getName();
}

public class User [2] Named {
    @Override
    public String [3]() {
        return "User";
    }
}
Drag options to blanks, or click blank then click option'
ANamed
Bimplements
CgetName
Dextends
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using extends instead of implements for interfaces.
Incorrect method name or signature.
Mismatching interface name.