0

Keywords

Description: Keywords
Number of Questions: 15
Created by:
Tags: Keywords Java/Oracle /C/C++ Java Inheritance and Constructor
Attempted 0/15 Correct 0 Score 0

Which Java keyword should be used with a data member to make it non-serializable?

  1. private

  2. public

  3. transient

  4. unserialize

  5. none of the above


Correct Option: C
Explanation:

This is the correct answer. If a data member is made transient, it will not be serialized.

Which of the following keywords is used to implement inheritance in Java?

  1. inheritance

  2. inherit

  3. extend

  4. extends


Correct Option: D
Explanation:

The keyword extends is used to implement the inheritance in Java.

Which of the following statements is correct? A. super keyword is used to access the constructor of superclass from subclass constructor. B. super keyword is used to access the variable of superclass from the subclass.

  1. Only A

  2. Only B

  3. Both A and B

  4. Neither A nor B


Correct Option: C
Explanation:

Both the given statements are true that is the super keyword is used to access the constructor of superclass and variable from the subclass.

Interface can be implemented using the ___________ keyword.

  1. implement

  2. implements

  3. extend

  4. extends


Correct Option: B
Explanation:

Interface can be implemented using the implements keyword because definition is not allowed within the interface. So, it has to be implemented.

When methods with the same name appears in both superclass and subclass, then only __________ method is invoked.

  1. subclass

  2. static

  3. final

  4. finalize


Correct Option: A
Explanation:

When methods with same name appears in both superclass and subclass, then only subclass method is invoked. So, it is said that the method of subclass overrides the method of superclass.

Character literals in java enclosed in____________quotes.

  1. single

  2. double

  3. without any quotes

  4. a and b

  5. none of the above


Correct Option: A
Explanation:

right

Which of the following does not represent a character literal in Java?

  1. 'c'

  2. 'r'

  3. 'n'

  4. a

  5. '5'


Correct Option: D
Explanation:

Though it is a digit, it is treated as a character because of single quotes. It is treated as a string in Java.

Which of the following is not used as Garbage Collection Algorithms in Java?

  1. Adaptive collectors

  2. Copying collectors

  3. Tracing collectors

  4. Destructor algorithm

  5. The train algorithm


Correct Option: D
Explanation:

Destructor is a method in Java, not an algorithm.

Which of the following keywords should be used to make a class level variable?

  1. final

  2. static

  3. private

  4. classlevel

  5. public


Correct Option: B
Explanation:

This is the correct answer.  The static keyword is used to  declare a variable class level.  For example, counters are made class level so that different class objects can access the same variable and perform actions on it.

All the variables must be __________ and initialized in the interface.

  1. static

  2. finalize

  3. final

  4. protected


Correct Option: C
Explanation:

All the variables within the interface must be final and initialized within the interface.

Which of the following is not a keyword of Java?

  1. static

  2. final

  3. protected

  4. virtual


Correct Option: D
Explanation:

There is no such keyword as virtual in Java. 

The protected access specifier works as ________ for outside world, but works as ________ for derived classes in Java.

  1. private and public

  2. public and private

  3. private and private

  4. public and public


Correct Option: A
Explanation:

The protected access specifier works as private for outside world, but works as public for derived classes in Java.

If the first statement of a constructor has the form ________, then the constructor calls another constructor of the same class.

  1. static

  2. this(parameter list)

  3. this

  4. static(parameter list)


Correct Option: B
Explanation:

If the first statement of a constructor has the form this(parameter list), then the constructor calls another constructor of the same class. For example: class Emp {     int m;     double n;     public Emp(int x)     {             this(789.89,x);      } } Here, this(789.89,x) statement calls the constructor Emp(double,int)

The protected access specifier is very useful in ___________ inheritance.

  1. simple

  2. multiple

  3. multilevel

  4. hierarchical


Correct Option: C
Explanation:

The protected access specifier is very useful in multilevel inheritance because the protected member of super class A can be accessed by the subclass C in the following way. A(Super Class)$\rightarrow$ B(Subclass of A) $\rightarrow$C(Subclass of B)

Which of the following statements regarding 'finally' block in Java is false?

  1. Before the termination of the program, JVM executes the 'finally' block (if any).

  2. The 'finally' block can be used for writing the cleanup code.

  3. The 'finally' block must be followed by try or catch block.

  4. There can be multiple 'finally' blocks for a try block.

  5. The 'finally' block is not executed if the program exists.


Correct Option: D
Explanation:

This is a false statement. There can only be one finally block for each try block. Since the statement is false about 'finally' block in Java, it is the correct alternative.

- Hide questions