It is a scjp question and I cannot compile the program.
Consider following classes:
//In File Other.java
package other;
public class Other
{public static String hello = "Hello";}
//In File Test.java
package testPackage;
class Test
{
public static void main(String[] args)
{
String hello = "Hello", lo = "lo";
System.out.print((testPackage.Other.hello == hello) + " "
; //line 1
System.out.print((other.Other.hello == hello) + " "
; //line 2
System.out.print((hello == ("Hel"+"lo"
) + " "
; //line 3
System.out.print((hello == ("Hel"+lo)) + " "
; //line 4
System.out.println(hello == ("Hel"+lo).intern()); //line 5
}
}
class Other
{ static String hello = "Hello";}
What will be the output of running class Test? Select 1 correct option
(1) false false true false true
(2) false true true false true
(3) true true true true true
(4) true true true false true
(5) None of the above
The answer is 4
I use winxp.
*** I cannot compile the program and type javac testPackageTest.java in dos prompt at directory n.
here is my file list
I have a directory n. Directory n contains two subdirectories testPackage and other. Subdirectory testPackage contains file Test.java. Subdirectory other contains file Other.java
*** I would like to ask why line1, line2 and line3 give true result?
Thanks for any help!
Consider following classes:
//In File Other.java
package other;
public class Other
{public static String hello = "Hello";}
//In File Test.java
package testPackage;
class Test
{
public static void main(String[] args)
{
String hello = "Hello", lo = "lo";
System.out.print((testPackage.Other.hello == hello) + " "
System.out.print((other.Other.hello == hello) + " "
System.out.print((hello == ("Hel"+"lo"
System.out.print((hello == ("Hel"+lo)) + " "
System.out.println(hello == ("Hel"+lo).intern()); //line 5
}
}
class Other
{ static String hello = "Hello";}
What will be the output of running class Test? Select 1 correct option
(1) false false true false true
(2) false true true false true
(3) true true true true true
(4) true true true false true
(5) None of the above
The answer is 4
I use winxp.
*** I cannot compile the program and type javac testPackageTest.java in dos prompt at directory n.
here is my file list
I have a directory n. Directory n contains two subdirectories testPackage and other. Subdirectory testPackage contains file Test.java. Subdirectory other contains file Other.java
*** I would like to ask why line1, line2 and line3 give true result?
Thanks for any help!