Java Questions and Answers Part-15

1. Static members are not inherited to subclass.
a) true
b) false

Answer: b
Explanation: Static members are also inherited to subclasses.

2. Which of the following is used for implementing inheritance through an interface?
a) inherited
b) using
c) extends
d) implements

Answer: d
Explanation: Interface is implemented using implements keyword. A concrete class must implement all the methods of an interface, else it must be declared abstract.

3. Which of the following is used for implementing inheritance through class?
a) inherited
b) using
c) extends
d) implements

Answer: c
Explanation: Class can be extended using extends keyword. One class can extend only one class. A final class cannot be extended.

4. What would be the result if a class extends two interfaces and both have a method with same name and signature? Lets assume that the class is not implementing that method.
a) Runtime error
b) Compile time error
c) Code runs successfully
d) First called method is executed successfully

Answer: b
Explanation: In case of such conflict, compiler will not be able to link a method call due to ambiguity. It will throw compile time error.

5. Does Java support multiple level inheritance?
a) True
b) False

Answer: a
Explanation: Java supports multiple level inheritance through implementing multiple interfaces.

6. Which of these class is superclass of String and StringBuffer class?
a) java.util
b) java.lang
c) ArrayList
d) None of the mentioned

Answer: b
Explanation: java.lang

7. Which of these operators can be used to concatenate two or more String objects?
a) +
b) +=
c) &
d) ||

Answer: a
Explanation: Operator + is used to concatenate strings, Example String s = “i ” + “like ” + “java”; String s contains “I like java”.

8. Which of this method of class String is used to obtain a length of String object?
a) get()
b) Sizeof()
c) lengthof()
d) length()

Answer: d
Explanation: Method length() of string class is used to get the length of the object which invoked method length().

9. Which of these method of class String is used to extract a single character from a String object?
a) CHARAT()
b) chatat()
c) charAt()
d) ChatAt()

Answer: c
Explanation: charAt()

10. Which of these constructors is used to create an empty String object?
a) String()
b) String(void)
c) String(0)
d) None of the mentioned

Answer: a
Explanation: String()