Search

Java Questions

1. What is the use of the "this" keyword in Java?

  1. Referring to the instance variable when a local variable has the same name
  2. Passing itself to the method of the same class
  3. Passing itself to another method
  4. Calling another constructor in constructor chaining

    Answer: a

    Description: "this" is an important keyword in java. It helps to distinguish between local variable and variables passed in the method as parameters.

2. Which type of Java application uses GUI components like AWT, Swing, and JavaFX?
  1. Web Applications
  2. Standalone Applications
  3. Mobile Applications
  4. Distributed Applications

Answer: b

Description: Standalone applications use GUI components such as AWT, Swing, and JavaFX for desktop environments.

3. What is the primary role of the javac command in Java?

  1. To execute Java applications
  2. To compile Java source code into bytecode
  3. To manage Java packages
  4. To optimize Java code

Answer: b

Description: The javac command is used to compile Java source code into bytecode.

4. What is the purpose of the final keyword in Java?

  1. To create a constant variable
  2. To prevent method overriding
  3. To prevent inheritance
  4. All of the above

Answer: d

Description: The final keyword can be used to create constants, prevent method overriding, and prevent class inheritance.

5) When an array is passed to a method, what does the method receive?

  1. The reference of the array
  2. A copy of the array
  3. Length of the array
  4. Copy of the first element

Answer: a

Description: When an array is passed to a method, the method receives a reference to the original array, allowing it to modify the array's elements directly.