0

Keywords

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

In Java, final keyword gives the same result as ________ declaration in C++.

  1. throw

  2. cout

  3. const

  4. cin


Correct Option: C
Explanation:

The final keyword declares the variable as a constant. The final variable has to be initialized only once. The same process is done in C++ by the keyword const.

What will be output of the following program?

class A {
 static{ 
  System.out.println("JAVA"); 
  System.exit(0); 
  }
}
  1. Compile time error

  2. Run time error

  3. Exception error

  4. JAVA

  5. 0


Correct Option: D
Explanation:

Correct! Because of JVM always execute instruction on the basis of priority so static block has higher priority than main method hence It will execute static block then after it will go to main method (which is essential for all the java programs to run) but here programmer written intelligently his program to get output.

In System.out.println(), the keyword out is the _________.

  1. class

  2. object

  3. method

  4. vriable


Correct Option: B
Explanation:

The keyword “out” is the object of System class.

Which of the following symbols is used for representing the XOR operator in Java?

  1. ~

  2. &

  3. ^


Correct Option: D
Explanation:

The ^ operator is used for representing the XOR operator in Java.

What will be output of the following program?

class A { 
  boolean b;
  public static void main(String arg[]){
    System.out.println(b);
  }
}
  1. compile time error

  2. true

  3. false

  4. runtime exception

  5. 0


Correct Option: A
Explanation:

Compile Time Error

Which of the following cannot be used as a method modifier?

  1. Private

  2. Generic

  3. Protected

  4. Synchronized

  5. All of the above


Correct Option: B
Explanation:

generic does not works as a modifier.

Which of the following statements is/are correct for static method in Java?

A. Static methods are always public. B. Static method cannot access directly non-static method of the same class.

  1. Only A

  2. Only B

  3. Both A and B

  4. Neither A nor B


Correct Option: B
Explanation:

It is not necessary that the static methods are always public. But it is true that static methods cannot access directly non-static method of the same class.

Which of the following is/are not keyword(s)?

  1. Switch

  2. Integer

  3. Default

  4. Boolean

  5. All of the above


Correct Option: B
Explanation:

This is not a keyword.

Which is a reserved keyword in java?

  1. Subclass

  2. Native

  3. Array

  4. None of theses

  5. All of these


Correct Option: B
Explanation:

Native is a Java keyword that is used in method declarations to specify that the method will not be implemented in another language, not in Java.

Which of the following statements is true regarding final keyword in Java?

  1. A final class can be extended by another class.

  2. A final method can be overridden when its class is inherited.

  3. A final variable's value cannot be changed.

  4. The keywords final and finally have the same meaning in Java.

  5. Final class can be abstract in Java.


Correct Option: C
Explanation:

This is the correct answer. A final variable is equivalent to a constant. Once a value is assigned to it, it cannot be changed.

What is the default value of referance type?

  1. 0

  2. -1

  3. 100

  4. null

  5. -100


Correct Option: D
Explanation:

Default value of reference type is null.

Which of the following is not a reserve word in Java?

  1. Transient

  2. Implements

  3. Include

  4. Instanceof

  5. All of the above


Correct Option: C
Explanation:

It is not a keyword in c.

Which of the following is a keyword in Java?

  1. Delete

  2. Exit

  3. Main

  4. Continue

  5. Next


Correct Option: D
Explanation:

Next is not a keyword in Java. Continue is a keyword in Java. Continue is used inside a loop to skip the current loop step and continue with the next loop step.

Which is a reserved word in Java programming language?

  1. Method

  2. Native

  3. Subclasses

  4. Reference

  5. Array


Correct Option: B
Explanation:

The word native is a valid keyword, used to modify a method declaration.

What will be the output of the program?

class Super
{ 
    public int i = 0; 

    public Super(String text) /* Line 4 */
    {
        i = 1; 
    } 
} 

class Sub extends Super
{
    public Sub(String text)
    {
        i = 2; 
    } 

    public static void main(String args[])
    {
        Sub sub = new Sub(Hello); 
        System.out.println(sub.i); 
    } 
}
  1. 0

  2. 1

  3. 2

  4. Compilation fails


Correct Option: D
Explanation:

A default no-args constructor is not created because there is a constructor supplied that has an argument, line 4. Therefore the sub-class constructor must explicitly make a call to the super class constructor:

- Hide questions