wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Interface + java-visual

Total questions: 88

Worksheet time: 44mins

Name
Class
Date
1.

What is the color of the water bottle in the image?

a)

Red

b)

Blue

c)

Green

d)

Yellow

2.

What is the name of the remote resource defined in the image?

a)

PetStore

b)

Pet

c)

CreatePet

d)

IdNotFound

3.

What is the output of the program?

a)

2000

b)

Have a good day

c)

Static method

d)

None of the above

4.

What is the purpose of the CallBackInterface interface?

a)

To allow the WorkerClass to notify the MainActivity when it has finished its task.

b)

To allow the MainActivity to control the WorkerClass's behavior.

c)

To allow the WorkerClass to access the MainActivity's data.

d)

To allow the MainActivity to access the WorkerClass's methods.

5.

What is the output of the displayInfo() method?

a)

Person Name: JOHN, Person Age: 32

b)

Person Name: JOHN, Person Age: 21

c)

Person Name: InterfaceExamples, Person Age: 32

d)

Person Name: InterfaceExamples, Person Age: 21

6.

What is the HTTP method used to add a new pet to the store?

a)

GET

b)

POST

c)

PUT

d)

DELETE

7.

Which of the following classes inherits from the Movable interface?

a)

MovablePoint

b)

MovableCircle

c)

Both MovablePoint and MovableCircle

d)

Neither MovablePoint nor MovableCircle

8.

What is the purpose of the ITable interface?

a)

To define the methods that must be implemented by any class that wants to be a table.

b)

To provide a way to access the data in a table.

c)

To allow different types of tables to be used in the same program.

d)

All of the above.

9.

Which of the following methods is declared as a private static method in the MyInterfaceInJava9 interface?

a)

printLines()

b)

method1()

c)

method2()

d)

mymethods()

10.

Which of the following classes inherits from the Animal class?

a)

Cat

b)

Dog

c)

Bird

d)

All of the above

11.

Which of the following methods is implemented in the MyClass class?

a)

method()

b)

method(double x)

c)

method(int x)

d)

method(char x)

12.

What is the output of the code?

a)

10

b)

20

c)

30

d)

40

13.

The main purpose of an interface in Java is to __________.

a)

Achieve abstraction.

b)

Support multiple inheritance.

c)

Achieve loose coupling.

d)

Provide a way to implement abstract classes.

14.

What is the keyword used to declare an interface in Java?

a)

interface

b)

class

c)

abstract

d)

static

15.

Which of the following is NOT a difference between a class and an interface in Java?

a)

A class can have concrete methods, while an interface cannot.

b)

A class can be instantiated, while an interface cannot.

c)

A class can extend another class, while an interface can extend multiple interfaces.

d)

A class can implement an interface, while an interface cannot implement a class.

16.

Which of the following methods is declared in the Bird interface in the image?

a)

breathe()

b)

chirp()

c)

equals(Object obj)

d)

getClass()

17.

Which of the following methods is implemented by the Vehicle class in the image?

a)

speedUp()

b)

changeGear()

c)

main()

d)

toString()

18.

What is the data type of the mark variable in the Father interface?

a)

int

b)

float

c)

double

d)

String

19.

What is the return type of the removeIf method in the Collection interface?

a)

boolean

b)

int

c)

String

d)

void

20.

What is the purpose of the endpoint variable in the code in the image?

a)

It stores the URL of the web service.

b)

It stores the name of the web service.

c)

It stores the port number of the web service.

d)

It stores the method name of the web service.

21.

What is the value of the name static final String in the image?

a)

interface

b)

interface1

c)

interface2

d)

interface3

22.

What is the name of the interface that is being implemented by the Bird class?

a)

Flyable

b)

Animal

c)

Bird

d)

CanFly

23.

What is the name of the new method that has been added to the image?

a)

stream()

b)

sort()

c)

add(E e)

d)

remove(Object o)

24.

What is the keyword used to declare a variable in an interface?

a)

static

b)

final

c)

public

d)

private

25.

What is the name of the class that is being extended by the MyListWMerge class?

a)

Mergeable

b)

Arraylist

c)

List

d)

Object

26.

Which of the following is NOT a collection interface in Java?

a)

Collection

b)

List

c)

Set

d)

Deque

27.

What is the data type of the speed variable in the Moveable interface?

a)

int

b)

float

c)

double

d)

String

28.

Which of the following methods is declared in the Employee interface?

a)

getData()

b)

setAge()

c)

getName()

d)

toString()

29.

What is the return type of the show() method in the InterfaceExample2 class?

a)

void

b)

int

c)

String

d)

boolean

30.

What is the return type of the add() method in the MyMath interface?

a)

int

b)

float

c)

double

d)

void

31.

What is the default value of the mark variable in the Father interface?

a)

100

b)

0

c)

null

d)

No default value

32.

What is the return type of the play() method in the MediaPlayer interface?

a)

void

b)

int

c)

String

d)

boolean

33.

What is the data type of the name variable in the CreditCard interface?

a)

String

b)

int

c)

float

d)

double

34.

What is the return type of the calculate() method in the SimpleInterest interface?

a)

double

b)

int

c)

String

d)

void

35.

What is the return type of the getArea() method in the Circle interface?

a)

int

b)

float

c)

double

d)

void

36.

What is the data type of the radius variable in the Circle class?

a)

int

b)

float

c)

double

d)

String

37.

Which of the following is not a method in the Circle class?

a)

getArea()

b)

getRadius()

c)

setRadius()

d)

draw()

38.

What is the data type of the x variable in the Point class?

a)

int

b)

float

c)

double

d)

String

39.

What is the return type of the getName() method in the Person class?

a)

String

b)

int

c)

float

d)

double

40.

What is the data type of the age variable in the Student class?

a)

int

b)

float

c)

double

d)

String

41.

What is the return type of the getMark() method in the Student class?

a)

int

b)

float

c)

double

d)

String

42.

What is the default value of the mark variable in the Student class?

a)

0

b)

100

c)

null

d)

No default value

43.

What is the return type of the add() method in the Calculator class?

a)

int

b)

float

c)

double

d)

void

44.

What is the return type of the show() method in the MyClass class?

a)

void

b)

int

c)

String

d)

double

45.

What is the keyword used to declare an interface in Java?

a)

class

b)

interface

c)

abstract

d)

static

46.

Which of the following keywords is used to declare a method in an interface?

a)

public

b)

abstract

c)

static

d)

final

47.

What is the keyword used to declare a constant in an interface in Java?

a)

public

b)

final

c)

static

d)

abstract

48.

Which of the following interfaces is a subinterface of the Collection interface?

a)

List

b)

Set

c)

Queue

d)

Map

49.

Which of the following statements is true about constructors in Java interfaces?

a)

Constructors are allowed in Java interfaces.

b)

Constructors are not allowed in Java interfaces.

c)

Constructors are allowed in Java interfaces, but they must be default constructors.

d)

Constructors are allowed in Java interfaces, but they must be parametrized constructors.

50.

Which of the following statements is true about the code in the image?

a)

The code compiles and runs without errors.

b)

The code compiles but throws an exception at runtime.

c)

The code does not compile because the inputLocation() method is abstract.

d)

The code does not compile because the inputLocation() method is not public.

51.

Why does the code in the image not compile?

a)

The interface SimpleFuncInterface is not a functional interface.

b)

The method doWork() is not abstract.

c)

The method isFunctional() is not abstract.

d)

The annotation @FunctionalInterface is not used correctly.

52.

What is the error message in the image?

a)

The interface DemoInterface must have a default method.

b)

The interface DemoInterface cannot have a default method.

c)

The interface DemoInterface must have a static method.

d)

The interface DemoInterface cannot have a static method.

53.

What is the output of the code in the image?

a)

Person Name: JOHN Person Age: 32 Employee Name: Michael

b)

Person Name: JOHN Person Age: 32

c)

Employee Name: Michael

d)

Nothing is printed

54.

What is the keyword used to declare a method in an interface?

a)

public

b)

abstract

c)

static

d)

final

55.

What is the keyword used to declare a constant in an interface in Java?

a)

public

b)

final

c)

static

d)

abstract

56.

What is the error message in the image?

a)

The interface TestInterface must have a default method.

b)

The interface TestInterface cannot have a default method.

c)

The interface TestInterface must have a static method.

d)

The interface TestInterface cannot have a static method.

57.

What is the purpose of the code in the image?

a)

To declare a marker interface.

b)

To declare a class that implements the MyMarker interface.

c)

To create an object of the MyMarker interface.

d)

To call the checkMarker() method.

58.

What is the keyword used to declare a default method in an interface in Java?

a)

public

b)

abstract

c)

static

d)

default

59.

What is the diamond problem in Java?

a)

A situation where a class inherits from two interfaces that have the same method with the same signature.

b)

A situation where a class inherits from two interfaces that have the same method with different signatures.

c)

A situation where a class inherits from two classes that have the same method with the same signature.

d)

A situation where a class inherits from two classes that have the same method with different signatures.

60.

What is the error message in the image?

a)

The class Employee must implement the method getName().

b)

The interface Human cannot have a default method.

c)

The interface EmployeeInfo cannot have a default method.

d)

The class Employee cannot inherit from two interfaces with the same method with the same signature.

61.

What is the keyword used to declare an interface in Java?

a)

class

b)

interface

c)

public

d)

static

62.

What is the error message in the image?

a)

The interface MyInterface cannot have a method with the same signature as the method getName() in the class Human.

b)

The class Human cannot have a method with the same signature as the method getName() in the interface MyInterface.

c)

The interface MyInterface cannot extend the class Human.

d)

The class Human cannot implement the interface MyInterface.

63.

What is the output of the code in the image?

a)

Hello, John!

b)

Hello, World!

c)

Nothing is printed.

d)

An error is thrown.

64.

What is the error message in the image?

a)

The interface MyInterface must have a default method.

b)

The interface MyInterface cannot have a default method.

c)

The interface MyInterface must have a static method.

d)

The interface MyInterface cannot have a static method.

65.

What is the error message in the image?

a)

The class MyClass must implement the method getName().

b)

The interface MyInterface cannot have a method with the same signature as the method getName() in the class MyClass.

c)

The class MyClass cannot have a method with the same signature as the method getName() in the interface MyInterface.

d)

The interface MyInterface cannot extend the class MyClass.

66.

What is the error message in the image?

a)

The interface MyInterface must have a method with the same signature as the method getName() in the class MyClass.

b)

The class MyClass cannot have a method with the same signature as the method getName() in the interface MyInterface.

c)

The interface MyInterface cannot extend the class MyClass.

d)

The class MyClass must implement the method getName().

67.

What is the output of the code in the image?

a)

Hello, John!

b)

Hello, World!

c)

Nothing is printed.

d)

An error is thrown.

68.

What is the error message in the image?

a)

The class Employee cannot extend the interface Human.

b)

The interface Human must have a method with the same signature as the method getName() in the class Employee.

c)

The class Employee cannot have a method with the same signature as the method getName() in the interface Human.

d)

The interface Human cannot have a default method.

69.

What is the error message in the image?

a)

The interface Human cannot have a default method.

b)

The class Employee cannot have a method with the same signature as the method getName() in the interface Human.

c)

The interface Human must have a method with the same signature as the method getName() in the class Employee.

d)

The class Employee cannot extend the interface Human.

70.

What is the warning message in the image?

a)

The method show() is abstract and must be implemented by the subclass.

b)

The method show() is not defined in the Sample interface.

c)

The method show() is not public and cannot be accessed from other classes.

d)

The class Employee cannot extend the interface Human.The method show() has a return type of void but does not return anything.

71.

What is the name of the method that is being overridden in the MyClass class in the image?

a)

display()

b)

print()

c)

show()

d)

toString()

72.

What is the name of the interface that the Activity class implements in the code snippet shown in the image?

a)

myLIB.Hellolistener

b)

android.app.Activity

d)

android.os.Bundle

73.

Which of the following is a static method in the image?

a)

public static void m1() in interface A

b)

main() method in interface Main

c)

main() method in abstract class B

d)

main() method in enum C

74.

What is the type of the variable UPPER_LIMIT in the image?

a)

Instance variable

b)

Static variable

c)

Final variable

d)

Constant variable

75.

Which of the following is the correct way to inherit from the Animal class and implement the Flyable interface in the image?

a)

class Bird extends Animal implements Flyable {}

b)

class Bird implements Flyable extends Animal {}

c)

class Bird extends Animal implements Flyable { public void fly() { } }

d)

class Bird implements Flyable { public void fly() { } } extends Animal

76.

What is the default value of the radius attribute in the Circle class in the image?

a)

0

b)

1

c)

5

d)

None of the above

77.

What is the name of the class that is being created in the image?

a)

Employee

b)

Person

c)

Human

d)

Worker

78.

What is the name of the interface that is being implemented in the image?

a)

Runnable

b)

Callable

c)

Thread

d)

Runnable and Callable

79.

What is the value of the variable mark in the image?

a)

1002

b)

2007

c)

300

d)

None of the above

80.

What is the name of the functional interface that takes an object of type T and returns an object of type R?

a)

Predicate

b)

Consumer

c)

Supplier

d)

Function

81.

What is the name of the Java IDE that is being used in the image?

a)

IntelliJ IDEA

b)

Eclipse

c)

NetBeans

d)

Visual Studio Code

82.

What is the name of the interface that the Books class implements in the image?

a)

Periodicals

b)

getPeriodicals

c)

getPublisher()

d)

getPublishDate()

83.

What is the name of the interface that the Books class implements in the image?

a)

Periodicals

b)

getPeriodicals

c)

getPublisher()

d)

getPublishDate()

84.

What is the type of the object that is being created in the image?

a)

Mobile

b)

OnePlus

c)

AbstractMobile

d)

Object

85.

Which of the following is the correct way to declare a variable of type List in the image?

a)

List<Integer> list = new ArrayList<>();

b)

List<Integer> list = new LinkedList<>();

c)

List<Integer> list = new Vector<>();

d)

List<Integer> list = new Stack<>();

86.

What is the purpose of the flowchart in the image?

a)

To show the process of writing a sentence.

b)

To show the different parts of a sentence.

c)

To show the different types of sentences.

d)

To show how to write a sentence in a specific style.

87.

What is the name of the class that is being created in the image?

a)

Laptop

b)

Notebook

c)

Computer

d)

Device

88.

What is the default value of the brand attribute in the Laptop class in the image?

a)

Apple

b)

Dell

c)

HP

d)

None of the above