- 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
- Which of the following is true about Java inheritance?
A) Java supports multiple inheritance.
B) Inheritance allows a class to inherit from multiple classes.
C) Private members of the superclass are accessible in the subclass.
D) In Java, every class must inherit from a superclass.
Answer: C) Private members of the superclass are accessible in the subclass.
- What is the output of the following code?
System.out.println(Math.ceil(5.2));
A) 5
B) 6
C) 5.2
D) Compiler error
Answer: B) 6
- In Java, which keyword is used to create an instance of a class?
A) new
B) instance
C) create
D) object
Answer: A) new
- What is the output of the following code?
System.out.println("Java".indexOf("v"));
A) 1
B) 2
C) 3
D) Compiler error
Answer: B) 2
- Which of the following statements about Java exceptions is true?
A) Checked exceptions are subclasses of RuntimeException
.
B) Unchecked exceptions must be handled by the programmer.
C) finally
block is not executed if an exception occurs.
D) throws
keyword is used to handle exceptions.
Answer: A) Checked exceptions are subclasses of RuntimeException
.
- 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 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".toUpperCase());
A) Java
B) java
C) JAVA
D) Compiler error
Answer: C) JAVA
- In Java, which keyword is used to define a subclass?
A) subclass
B) sub
C) extends
D) inherits
Answer: C) extends
Comments