Strings - Study Mode

[#96] What will be the output of the following Java program? class String_demo
{
public static void main(String args[])
{
char chars[] = {'a', 'b', 'c'}
String s = new String(chars)
System.out.println(s)
}
}
Correct Answer

(D) abc

[#97] What will be the output of the following Java program? class output
{
public static void main(String args[])
{
String s1 = "one"
String s2 = s1 + " two"
System.out.println(s2)
}
}
Correct Answer

(C) one two

[#98] The output of the following fraction of code is public class Test{
public static void main(String args[]){
String s1 = new String("Hello")
String s2 = new String("Hellow")
System.out.println(s1 = s2)
}
}
Correct Answer

(B) Hellow

Explanation

Solution: The output of the given code will be: In the code, two String objects s1 and s2 are created with the values "Hello" and "Hellow" (note the typo in "Hellow"), respectively. Then, the System.out.println() statement prints the result of the assignment s1 = s2 . This assignment sets the value of s1 to the same value as s2 , which is "Hellow". As a result, the println statement prints the value of s1 , which is "Hellow".

[#99] What will be the output of the following program code? class LogicalCompare{
public static void main(String args[]){
String str1 = new String("OKAY")
String str2 = new String(str1)
System.out.println(str1 == str2)
}
}
Correct Answer

(B) false

[#100] What will be the output of the following program? public class Test{
public static void main(String args[]){
String s1 = "java"
String s2 = "java"
System.out.println(s1.equals(s2))
System.out.println(s1 == s2)
}
}
Correct Answer

(D) true true