MCQ on Java keywords

Q) Correct statement about a class and interface is/are
  1. An interface can extend multiple interfaces
  2. A class can implement multiple interfaces.
  3. Java support multiple inheritance using interfaces.
  4. All of the above.
View Answer
Answer: D


Q) False statements about an Abstract class in java
  1. Abstract class act as a base class and can be extended
  2. Abstract class cannot be instantiated.
  3. It can contain only abstract methods.
  4. All of them are correct
View Answer
Answer: C
An abstract class in java can have both abstract and non-abstract methods.

Q) Correct differences between throw and throws in java is/are
  1. throw keyword is used to throw an exception explicitly whereas throws clause is used to declare an exception.
  2. By using Throw keyword, we cannot throw more than one exception but using throws we can declare multiple exceptions
  3. throw is used inside method body to invoke an exception and throws clause is used in method declaration (signature).
  4. All of them are correct.
View Answer
Answer: D

Q) Readonly variables in java
  1. Can be modified at runtime in non static constructor only.
  2. Can be modified from both method and constructor.
  3. Can never be modified as it behave as constant variable
  4. All are correct.
View Answer
Answer: A
Readonly variable can be modified in non-static constructor at run time.
const variable can never be modified across the program once initialized.

Read difference between readonly and const with example in C sharp

Leave a Comment