NEW
Font size
Worksheetsabstraction in java
Total questions: 15
Worksheet time: 8mins
Give an example of a real-world scenario where abstraction is used in Java.
Designing a traffic light system for a city
Developing a recipe management system for a restaurant
Using a bank account class to represent a customer's account
Creating a shopping cart for an online store
What is the difference between abstract class and interface in Java?
Both have different capabilities and serve different purposes in Java.
Interfaces can have method implementations
Abstract class cannot have abstract methods
They are exactly the same
How do you declare an abstract method in Java?
public abstract void methodName();
public void methodName() = 0;
public void abstract methodName();
abstract public void methodName() {}
What is the main purpose of an abstract class?
A. To provide a base class that other classes can extend and share common functionality
B. To create a class that cannot be extended
C. To create a class with only static members
D. To define multiple classes with the same name
What is the default access modifier for methods in an interface?
A. public
B. protected
C. private
D. package-private
Can an interface extend another interface?
A. Yes
B. No
C. Only if it is abstract
D. Only if it is final
Can an interface contain static methods in Java?
A. Yes
B. No
C. Only if they are abstract
D. Only if they are private
Which keyword is used to declare an abstract class in Java?
A. interface
B. extends
C. abstract
D. implements
Which of the following can an abstract class contain?
A. Only abstract methods
B. Only concrete methods
C. Both abstract and concrete methods
D. Only static methods
Which keyword is used to declare an interface in Java?
A. class
B. abstract
C. interface
D. implements
Interfaces can contain fields that are not final.
FALSE
TRUE
An abstract class can have final methods.
TRUE
FALSE
A class can extend multiple abstract classes in Java.
TRUE
FALSE
A class that extends an abstract class must implement all abstract methods of the superclass.
TRUE
FALSE
All methods in an interface are abstract by default.
FALSE
TRUE
