253). String in Java is a?
[A]class
[B]object
[C]variable
[D]character array
Show Answer
Correct Answer: class
Notes:
Answer: a
Explanation: None.
254). Which of these method of String class is used to obtain character at specified index?
[A]char()
[B] Charat()
[C]charat()
[D]charAt()
Show Answer
Correct Answer: charAt()
Notes:
Answer: d
Explanation: None.
255). Which of these keywords is used to refer to member of base class from a subclass?
[A]upper
[B]super
[C]this
[D] none of the mentioned
Show Answer
Correct Answer: super
Notes:
Answer: b
Explanation: Whenever a subclass needs to refer to its immediate superclass, it can do so by use of the keyword super.
256). Which of these method of String class can be used to test to strings for equality?
[A]isequal()
[B]isequals()
[C]equal()
[D]equals()
Show Answer
Correct Answer: equals()
Notes:
Answer: d
Explanation: None.
257). Which of the following statements are incorrect?
[A]String is a class
[B]Strings in java are mutable
[C]Every string is an object of class String
[D]Java defines a peer class of String, called StringBuffer, which allows string to be altered
Show Answer
Correct Answer: Strings in java are mutable
Notes:
Answer: b
Explanation: Strings in Java are immutable that is they can not be modified.
258). What will be the output of the following Java program?
class string_demo
{
public static void main(String args[])
{
String obj = "I" + "like" + "Java";
System.out.println(obj);
}
}
[A]I
[B]like
[C]Java
[D]IlikeJava
Show Answer
Correct Answer: IlikeJava
Notes:
Answer: d
Explanation: Java defines an operator +, it is used to concatenate strings.
output:$ javac string_demo.java
$ java string_demo
IlikeJava
259). What will be the output of the following Java program?
class string_class
{
public static void main(String args[])
{
String obj = "I LIKE JAVA";
System.out.println(obj.charAt(3));
}
}
Show Answer
Correct Answer: I
Notes:
Answer: a
Explanation: charAt() is a method of class String which gives the character specified by the index. obj.charAt(3) gives 4th character i:e I.
output:
$ javac string_class.java
$ java string_class
I
260). What will be the output of the following Java program?
class string_class
{
public static void main(String args[])
{
String obj = "I LIKE JAVA";
System.out.println(obj.length());
}
}
Show Answer
Correct Answer: 11
Notes:
Answer: c
Explanation: None.
output:
$ javac string_class.java
$ java string_class
11
261). What will be the output of the following Java program?
class string_class
{
public static void main(String args[])
{
String obj = "hello";
String obj1 = "world";
String obj2 = obj;
obj2 = " world";
System.out.println(obj + " " + obj2);
}
}
[A]hello hello
[B] world world
[C]hello world
[D]world hello
Show Answer
Correct Answer: hello world
Notes:
Answer: c
Explanation: None.
output:
$ javac string_class.java
$ java string_class
hello world
262). What will be the output of the following Java program?
class string_class
{
public static void main(String args[])
{
String obj = "hello";
String obj1 = "world";
String obj2 = "hello";
System.out.println(obj.equals(obj1) + " " + obj.equals(obj2));
}
}
[A] false false
[B]true true
[C] true false
[D]false true
Show Answer
Correct Answer: false true
Notes:
Answer: d
Explanation: equals() is method of class String, it is used to check equality of two String objects, if they are equal, true is retuned else false.
output:
$ javac string_class.java
$ java string_class
false true