Create New Post

Java MCQs - 12

  1. What is the output of the following code?
System.out.println("Java".endsWith("va")); 

A) true
B) false
C) Compiler error
D) Runtime error

Answer: A) true

  1. Which of the following is NOT a valid Java access modifier?

A) private
B) default
C) protected
D) internal

Answer: D) internal

  1. What is the output of the following code?
String str = "Java"; str += " Programming"; System.out.println(str); 

A) Java
B) Programming
C) JavaProgramming
D) Compiler error

Answer: C) JavaProgramming

  1. In Java, which of the following statements is true about method parameters?

A) Method parameters can have a default value.
B) Method parameters can be marked as final.
C) Method parameters can only be of primitive data types.
D) Method parameters are always passed by reference.

Answer: B) Method parameters can be marked as final.

  1. What is the output of the following code?
System.out.println("Java".replace('a', 'i')); 

A) Java
B) Jivi
C) Javai
D) Jivi

Answer: B) Jivi

  1. Which of the following statements about Java exceptions is true?

A) Checked exceptions are subclasses of RuntimeException.
B) Unchecked exceptions must be caught using a try-catch block.
C) Exception handling is done at compile time.
D) Exception handling is mandatory in Java.

Answer: A) Checked exceptions are subclasses of RuntimeException.

  1. What is the output of the following code?
System.out.println("Java".toUpperCase()); 

A) Java
B) java
C) JAVA
D) Compiler error

Answer: C) JAVA

  1. Which of the following is NOT a valid Java data type?

A) boolean
B) char
C) string
D) double

Answer: C) string

  1. What is the output of the following code?
System.out.println("Java".substring(1, 3)); 

A) Jav
B) av
C) ava
D) Compiler error

Answer: C) ava

  1. In Java, which keyword is used to define a subclass?

A) subclass
B) sub
C) extends
D) inherits

Answer: C) extends

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

95066