Abstraction

1.What is the primary purpose of abstraction in Java?
  • A. To hide the implementation details and show only necessary functionality
  • B. To increase the size of a Java program
  • C. To allow direct access to all variables in a class
  • D. To make all methods public

To hide the implementation details and show only necessary functionality

To hide the implementation details and show only necessary functionality

2.Which of the following best demonstrates abstraction?
  • A. A class with all variables as public
  • B. A method that provides functionality but hides internal implementation
  • C. A program where all methods are fully implemented
  • D. A method that allows direct modification of all attributes

A method that provides functionality but hides internal implementation

A method that provides functionality but hides internal implementation

3.Which Java feature is most related to abstraction?
  • A. Polymorphism
  • B. Garbage Collection
  • C. Multiple inheritance
  • D. Method overriding

Method overriding

Method overriding

4.Which of the following best demonstrates the concept of an abstract method?
  • A. A method with a defined body
  • B. A method with only a declaration and no body
  • C. A method that cannot be inherited
  • D. A method that can only be private

A method with only a declaration and no body

A method with only a declaration and no body

5.What will happen if an abstract class does not have any abstract methods?
  • A. It cannot be compiled
  • B. It can still be instantiated
  • C. It can be useful for enforcing a specific behaviour without forcing implementation
  • D. It will always throw an error at runtime

It can be useful for enforcing a specific behaviour without forcing implementation

It can be useful for enforcing a specific behaviour without forcing implementation