What Will Be The Output Of The Following Java Codep Pre #642
What will be the output of the following Java code?</p> <pre><code class="language-java"> public class StringProgram { public static class Compare { static String a,b; Compare(String x, String y) { a=x; b=y; } public static void compare() { if(a==b) System.out.println("The strings are equal"); else System.out.println("The strings aren't equal"); } } public static void main(String[] args) { String a = new String("NVAEducation"); String b = new String("NVAEducation"); StringProgram.Compare i = new StringProgram.Compare(a, b); i.compare(); } } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs111 OOP Object Oriented Programming Java. It can also be found in gs gs111 Types of Classes (Using Java) - Static Class - Quiz No.1.
What will be the output of the following Java code?
public class StringProgram { public static class Compare { static String a,b; Compare(String x, String y) { a=x; b=y; } public static void compare() { if(a==b) System.out.println("The strings are equal"); else System.out.println("The strings aren't equal"); } } public static void main(String[] args) { String a = new String("NVAEducation"); String b = new String("NVAEducation"); StringProgram.Compare i = new StringProgram.Compare(a, b); i.compare(); } }
Runtime Error
Compilation Error
The strings are equal
The strings aren’t equal