//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.
About Question com.enthuware.ets.scjp.v6.2.325 :
Moderator: admin
-
- Posts: 1
- Joined: Mon Feb 17, 2014 5:56 pm
- Contact:
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
The main method has to be public. There is no restriction on the class.
-
- Posts: 27
- Joined: Mon Sep 22, 2014 1:30 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
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.
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.
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
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.
-
- Posts: 3
- Joined: Thu Jan 14, 2021 9:57 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
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
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
-
- Site Admin
- Posts: 10385
- Joined: Fri Sep 10, 2010 9:26 pm
- Contact:
Re: About Question com.enthuware.ets.scjp.v6.2.325 :
Scroll down. The last line of the code snippet declares class Other.
Who is online
Users browsing this forum: No registered users and 9 guests