- 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
- Which of the following is NOT a valid Java access modifier?
A) private
B) default
C) protected
D) internal
Answer: D) internal
- 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
- 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
.
- 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
- 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
.
- 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
- Which of the following is NOT a valid Java data type?
A) boolean
B) char
C) string
D) double
Answer: C) string
- 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
- In Java, which keyword is used to define a subclass?
A) subclass
B) sub
C) extends
D) inherits
Answer: C) extends
Comments