Java Questions are in bold. Which of these is a valid way to create a String? (c
ID: 3721628 • Letter: J
Question
Java Questions are in bold.
Which of these is a valid way to create a String? (choose all that apply)
Question 1 options:
String s = "Hello";
String s = new String("Hello");
char[] arr = {'H', 'e', 'l', 'l', 'o'};String s = new String(arr);
String s1 = new String("Hello"); String s2 = s1;
Given the code below, which of these will return the boolean value true?
String s1 = new String( hello ); String s2 = new String( hello );
Question 2 options:
s1 == s2
s1.equals(s2)
s1.compareTo(s2)
s1.sameAs(s2)
What is the output of the following code?
String s1 = This is Java ;if (s1.contains( Java )) {s1 = s1.replaceAll( Java , fun );} System.out.println(s1);
Question 3 options:
Java
fun
This is Java
This is fun
Does the following code show method overriding or method overloading?
public class A {public void echo(String s) { System.out.println(s);}} public class B extends A {public void echo(String s, int x) {for (int i=0; i}}}
overriding
overloading
String s = "Hello";
String s = new String("Hello");
char[] arr = {'H', 'e', 'l', 'l', 'o'};String s = new String(arr);
String s1 = new String("Hello"); String s2 = s1;
Given the code below, which of these will return the boolean value true?
String s1 = new String( hello ); String s2 = new String( hello );
Question 2 options:
s1 == s2
s1.equals(s2)
s1.compareTo(s2)
s1.sameAs(s2)
What is the output of the following code?
String s1 = This is Java ;if (s1.contains( Java )) {s1 = s1.replaceAll( Java , fun );} System.out.println(s1);
Question 3 options:
Java
fun
This is Java
This is fun
Does the following code show method overriding or method overloading?
public class A {public void echo(String s) { System.out.println(s);}} public class B extends A {public void echo(String s, int x) {for (int i=0; i}}}
overriding
overloading
Explanation / Answer
1)All the given options are valid to create a string.
2)Answer is B.
s1.equals(s2). This will return True.
3)Answer is D.
As the statement contains Java, it will replace it as Fun. so the output is "This is Fun"
4)Answer is Overloading
There are two function names with different parameter sets, This is called as Overloading of function.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.