0
0
Javaprogramming~10 mins

Interface declaration 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 Vehicle.

Java
public [1] Vehicle {
    void start();
}
Drag options to blanks, or click blank then click option'
Ainterface
Bclass
Cenum
Dabstract
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'class' instead of 'interface' to declare an interface.
Using 'abstract' keyword alone without 'interface'.
2fill in blank
medium

Complete the code to declare a method named stop in the interface.

Java
public interface Machine {
    [1] stop();
}
Drag options to blanks, or click blank then click option'
Avoid
Bint
Cstatic
Dfinal
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'int' as return type when no value is returned.
Using 'static' or 'final' keywords in method declaration inside interface.
3fill in blank
hard

Complete the code to explicitly declare an abstract method named reset in the interface.

Java
public interface Device {
    public [1] void reset();
}
Drag options to blanks, or click blank then click option'
Aprivate
Babstract
Cfinal
Dstatic
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'final' keyword which is not allowed in interface methods.
Using 'private' access modifier which is invalid in interfaces.
4fill in blank
hard

Fill both blanks to declare an interface named Calculator with a method calculate returning an int.

Java
public [1] Calculator {
    [2] calculate();
}
Drag options to blanks, or click blank then click option'
Ainterface
Bvoid
Cint
Dclass
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'class' instead of 'interface' for the first blank.
Using 'void' as return type when an int is expected.
5fill in blank
hard

Fill all three blanks to declare an interface named Printer with a method print that takes a String parameter and returns nothing.

Java
public [1] Printer {
    [2] print([3] message);
}
Drag options to blanks, or click blank then click option'
Ainterface
Bvoid
CString
Dclass
Attempts:
3 left
πŸ’‘ Hint
Common Mistakes
Using 'class' instead of 'interface' for the first blank.
Using 'int' or other types instead of 'void' for the return type.
Using incorrect parameter types instead of 'String'.