Page 1 of 1
About Question com.enthuware.ets.scjp.v6.2.325 :
Posted: Mon Feb 17, 2014 6:32 pm
by kantharos
//In File Test.java
package testPackage;
import other.*;
class Test
{
public static void main(String[] args)
{
// ...
}
}
class Other { static String hello = "Hello"; }
What will be the output of running class Test?
IMO NOTHING, because it won't run, as class Test is not public.
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
Posted: Mon Feb 17, 2014 7:42 pm
by admin
The main method has to be public. There is no restriction on the class.
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
Posted: Sat Oct 25, 2014 2:44 pm
by piotrkmiotczyk
These are the six facts on Strings:
1. Literal strings within the same class in the same package represent references to the same String object.
2. Literal strings within different classes in the same package represent references to the same String object.
3. Literal strings within different classes in different packages likewise represent references to the same String object.
How does it relate to an explanation earlier suggesting that interning pool can get GC'd with an object/class? Are they stored per-object, per-class or globally? If globally, as suggested above, I don't see a way for objects in the pool to get GC'd.
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
Posted: Sat Oct 25, 2014 7:02 pm
by admin
I am sorry but I did not understand your question. interned Strings are not GCed and literal strings are interned. So I am not sure what is the issue.
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
Posted: Wed Jan 20, 2021 8:40 am
by unranked
package other;
public class Other { public static String hello = "Hello";}
package testPackage;
public class Test {
public static void main(String[] args) {
System.out.println(testPackage.Other.hello == hello); // line 1
}
}
but there's no Other class in testPackage. It must not compile
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
Posted: Wed Jan 20, 2021 12:00 pm
by admin
Scroll down. The last line of the code snippet declares class Other.