wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

abstraction in java

Total questions: 15

Worksheet time: 8mins

Name
Class
Date
1.

Give an example of a real-world scenario where abstraction is used in Java.

a)

Designing a traffic light system for a city

b)

Developing a recipe management system for a restaurant

c)

Using a bank account class to represent a customer's account

d)

Creating a shopping cart for an online store

2.

What is the difference between abstract class and interface in Java?

a)

Both have different capabilities and serve different purposes in Java.

b)

Interfaces can have method implementations

c)

Abstract class cannot have abstract methods

d)

They are exactly the same

3.

How do you declare an abstract method in Java?

a)

public abstract void methodName();

b)

public void methodName() = 0;

c)

public void abstract methodName();

d)

abstract public void methodName() {}

4.

What is the main purpose of an abstract class?

a)

A. To provide a base class that other classes can extend and share common functionality

b)

B. To create a class that cannot be extended

c)

C. To create a class with only static members

d)

D. To define multiple classes with the same name

5.

What is the default access modifier for methods in an interface?

a)

A. public

b)

B. protected

c)

C. private

d)

D. package-private

6.

Can an interface extend another interface?

a)

A. Yes

b)

B. No

c)

C. Only if it is abstract

d)

D. Only if it is final

7.

Can an interface contain static methods in Java?

a)

A. Yes

b)

B. No

c)

C. Only if they are abstract

d)

D. Only if they are private

8.

Which keyword is used to declare an abstract class in Java?

a)

A. interface

b)

B. extends

c)

C. abstract

d)

D. implements

9.

Which of the following can an abstract class contain?

a)

A. Only abstract methods

b)

B. Only concrete methods

c)

C. Both abstract and concrete methods

d)

D. Only static methods

10.

Which keyword is used to declare an interface in Java?

a)

A. class

b)

B. abstract

c)

C. interface

d)

D. implements

11.

Interfaces can contain fields that are not final.

a)

FALSE

b)

TRUE

12.

An abstract class can have final methods.

a)

TRUE

b)

FALSE

13.

A class can extend multiple abstract classes in Java.

a)

TRUE

b)

FALSE

14.

A class that extends an abstract class must implement all abstract methods of the superclass.

a)

TRUE

b)

FALSE

15.

All methods in an interface are abstract by default.

a)

FALSE

b)

TRUE