Q) Final keyword in java is used with
  1. class
  2. class fields
  3. class methods
  4. All of the above

Answer: 4
Don’t want somewhere in the program to change class fields, then make it final.
don’t want to allow a class to be inherited, then make the class final
want to allow another class to inherit method of a class but don’t allow them to override it then make the method final. Read complete notes on final keyword in java with example


Q) False statement about final method in java
  1. Value of final variable cannot be changed once initialized.
  2. Final method is inherited but we cannot override it
  3. If you make a class final then you cannot extend the class
  4. Constructor can be declared as final.

Answer: 4
final variable act as a const, hence cannot be changed. final method we make to stop another class to override it. Class is made final to restrict, so, it cannot be inherited. Constructor cannot be final as they cannot be inherited.


Q) Super keyword in java is used to
  1. Refer immediate parent class instance variables.
  2. Invoke immediate parent class methods.
  3. Invoke immediate parent class constructor.
  4. All

Answer: 4


Q) True statement about extending a class in java is
  1. A class can extends only one another class
  2. A class can extends multiple classes.
  3. A class can extends multiple interfaces.
  4. None

Answer: 2
A class can extends only one another class and cannot extend multiple classes as java does not support multiple inheritance for classes.
A class does not extends interfaces but implement them, hence, answer C is incorrect. However, multiple inheritance in java is supported for interfaces. Means. you can implement multiple inheritance using interface.


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.

Answer: 4


Related Posts