13 What is the difference between data abstraction and encapsulation?
Data abstraction is the ability to hide unwanted information.
The encapsulation refers to the ability to hide the data as well as the method together.
14. What are the differences between interfaces and abstract classes?
An abstract class can support both abstract and non-abstract methods. However, the interface allows only abstract methods.
In the case of an abstract class, both final and non-final variables are supported, but the interface has variables that are defined as final by default.
The abstract class can have private, and public attributes, but interfaces have attributes as public by default.
15. What is a try-catch block?
A try-catch block is used for exception handling, and the statements that may cause a potential error are enclosed in a try block
. When an exception is thrown, it is caught by the catch block
, where the logic to handle an exception is placed.
The try-catch blocks are usually finished by using a finally block. A ‘finally’ block is used for executing essential statements such as to free the memory, close files, or database connections, even if an exception occurs. The finally
block always runs.
16. What is an exception?
An exception is a special event, which is raised during the execution of a program at runtime if there is an error during the execution. The reason for the exception is mainly due to a position in the program, where the user wants to do something for which the program is not specified, like undesirable input. The exceptions include a message with the details about the error that occurred.
Errors and exceptions are different, and an error means a problem that the program should not catch while the exception implies a condition that should be caught by the program.
In OOP there is a mechanism used for handling the exceptions raised during program execution, called exception handling. It allows for the graceful handling of undesirable results.